概述
NaN的特点:
1.NaN是数字类型,但不是数字;
2.程序中出现NaN说明进行了非法的运算操作;
3.NaN是false;
4.NaN与自己不相等。
isNaN()方法解读:
判断括号内的内容在Number()方法转换之后,是否是NaN。
若转换后是NaN,则返回true;若不是,则返回false。
特点:isNaN()讨厌数字,但不讨厌数字类型NaN,它有一个可靠的鉴定师:Number()
eg:
alert( isNaN(250) ); //false 250本来就是数字
alert( isNaN('250') ); //false ‘250’在Number()转换后是数字
alert( isNaN( [] ) ); //false []在Number()转换后是数字
alert( isNaN( ‘abc’ ) ); //true 'abc'在Number()转换后是NaN
alert( isNaN( {} ) ); //true {}在Number()转换后是NaN
alert( isNaN( function(){ alert(1) } ) ); //true 函数类型在Number()转换后是NaN
下列表达式返回true的选项为( D )
A. alert(!‘false’);
B. alert(!true);
C. alert(isNaN(false));
D. alert(isNaN(‘true’));
最后
以上就是活力小蝴蝶为你收集整理的NaN,isNaN()总结的全部内容,希望文章能够帮你解决NaN,isNaN()总结所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复