js基本功——数据类型
1,number
数字类型包含整数,小数,NaN 和 Infinity
alert(typeof(123));
alert(typeof(1.23));
2,string
alert(typeof("123"));
3,object
数组 对象 和 null 均属于对象类型
alert(typeof([1,2,3]));
alert(typeof({a:1,b:2}));
js中,一切皆对象
4,boolean
true / false
5,undefined
var s;
alert(typeof(s));
注解:
NaN,指错误的数字类型,比如:
alert(Number("abc"));
Infitity,指正无穷大,如
alert(1/0);
undefined,表示一个未被定义的变量值
变量被声明了还没有赋值,就为undefined
调用函数时应该提供的参数还没有提供,该参数就等于undefined
对象没有赋值的属性,该属性的值就等于undefined
函数没有返回值,默认返回undefined
null,表示一个被定义了但其值为空的变量但值。
作为函数的参数,表示函数的参数不是对象
作为对象原型链的终点 alert(Object.getPrototypeOf(Object.prototype));
定义一个值为null是合理的,但定义为undefined不合理(var name = null)

浙公网安备 33010602011771号