1.NaN与任何东西都不相等,即便是它自己本身。
因此,当判数值类型是否是NaN时,不能用NaN==NaN来作为判断条件。
document.write(NaN==NaN);输出结果为false;
所以,用isNaN();作为判断即可。
document.write(isNaN(“bb”)); //输出 “true”,因为bb未定义,也没用赋值,不是一个数值
document.write(isNaN(“666”)); //输出 “false”
NAN not a number
2.NaN的数字类型是Number。
document.write(typeof(NaN));输出 Number
document.write(typeof(Object));输出 function
document.write(typeof(object));输出 undefine
document.write(typeof(null));输出object //这是因为null被认为是一个对象的占位符(一个对象类型输出也是object)
例如:function cs(){
}
var aa=new cs();
document.write(typeof(null));
document.write(typeof(aa));//两个输出结果都是object
document.write(typeof(undefined));输出undefined
undefined实际上是从null生成的,所有两者定义为相等,因此document.write(undefined==null)输出true,但是二者还是有区别的,null是完全为空,undefined是指未定义,因此document.write(undefined===null);输出false;
3.数据类型转换,Number与paresInt,typeof
document.write(Number(""));输出 0;
document.write(Number(null));输出0;//转化为数据时为0
另外
document.write(Number("aa"));输出NaN//""认为字符串,即使给aa定义一个数值,也会输出NAN
document.write(Number(aa));直接报错//aa未定义,当给aa定义一个数值后就会输出该数值
parseInt将字符串(即输入)(String)类型转为整数类型。即输出的为整数或者NAN
Number() 函数把对象(即输入)(Object)的值转换为数字。即输出的为数字(可为整数或者小数)或者NAN
typeof,是用来判断数据类型,即输出值为数据类型,Number,NaN,undefined...//不会有unll出现
4.两个以上typeof的输出是String
5.对象输出
function foo(){
}
var c=new foo();
document.write({});//[object Object] 花括号被认为对象
document.write(c);//[object Object]