js基本数据类型、隐式转换

基本数据类型:Number、Boolean、String、Object、Undefined、Null、Symbol

1、Undefined类型

    声明但未初始化,默认值为undefined,转为数值时为 NaN

var m;
alert(typeof m);  //undefined
alert(typeof n);  //undefined

2、Null类型

    空对象指针,所以 typeof 结果为 object ,转为数值时为 0 

alert(null == undefined);  //true
alert(null === undefined);  //false

3、Boolean类型

    true/false,Boolean() 强制转换为布尔类型

    String:非空为true,“”为false;

    Number:非0数字值(包括无穷大)为true,0或NaN为false;

    Object:任意对象为true,null为false;

    Undefined:直接为false;

4、Number类型

    isFinite() 是否有穷

alert(NaN == NaN); //false

    isNaN() 是否不是数值,Number()、parseInt()、parseFloat()强制转换

    Number():true:1,false:0,undefined:NaN,null:0,空串:0,只包含数字串:对应数值,十六进制串:对应十进制,其他串:NaN,对象:先调用valueOf(),转换,若结果为NaN,调用toString()再转换

    parseInt():

parseInt("");  //NaN
parseInt('1234blue'); //1234
parseInt('0xA');  //10
parseInt(22.5);  //22
parseInt('070');  //70(es6)

    parseFloat():

    只能转化为十进制,hulue前导0,任意16进制都转为0

5、String类型

    String(),null:“null”,undefined:“undefined”,其他调用toString()方法

6、Object类型



猜你喜欢

转载自blog.csdn.net/wwjwy123/article/details/80889668