<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script>
/*
* 实参<形参 多余形参==undefined
* 实参>形参 多余实参被忽略
*/
var f = function (x, y) {
console.log('length:' + arguments.length);
console.log(arguments.callee);
console.log('x:' + x + ' y:' + y);
for (var i = 0, len = arguments.length; i < len; i++) {
console.log(i + ':' + arguments[i]);
}
};
f(1);
f(1, 2, 3);
// 对未初始化的变量及未声明的变量使用typeof运算符均会返回undefined
console.log(typeof a); // undefined
var b;
console.log(typeof b); // undefined
// 没有必要将变量值显示声明undefined声明空对象时应将其值赋值为null
var c = null;
console.log(typeof c); // object
// undefined派生于null因此在使用==进行比较时会返回true
console.log(undefined == null);
// boolean
var d = 2;
console.log(typeof Boolean(d));
// 空字符串、0、NaN、null、undefined为false
console.log(Boolean(''));
console.log(Boolean(0));
console.log(Boolean(NaN));
console.log(Boolean(null));
console.log(Boolean(undefined));
console.log(Boolean(!''));
console.log(Boolean(!0));
console.log(Boolean(!NaN));
console.log(Boolean(!null));
console.log(Boolean(!undefined));
// 单引号与双引号不能交叉使用
console.log('123一二三\n'.length);
console.log('\\\"\"\'\'');
// toString() number boolean string object
var e = 22;
console.log(e.toString() === '22');
e = false;
console.log(e.toString() === 'false');
e = '22';
console.log(e.toString() === '22');
e = {'e': e};
console.log(e.toString());
console.log(String(22) === '22');
// NaN Not a Number 非数值 任何涉及NaN的操作都将返回NaN NaN与任何数值都不相等包括其自身
console.log(isNaN('abc')); // true 不能转换为数值
// Number() 空字符串0 其他格式字符串NaN
console.log(Number(true)); // 1
console.log(Number(false)); // 0
console.log(Number(null)); // 0
console.log(Number(undefined)); // NaN
console.log(parseInt('2.22') === 2);
console.log(parseFloat('2.22') === 2.22);
</script>
</body>
</html>