js内置对象isNaN

但如果isNaN函数判断的值不是number类型,那么isNaN函数判断之前会把值先转换成number类型,然后才会对这个转换结果是否是NaN进行判断,因为会出现很多特殊情况

1.空字符:

 isNaN("") = isNaN(Number("")) = isNaN(0) = false

2.布尔值:

isNaN(true||false) = isNaN(Number(true||false)) = isNaN(1||0) = false

3.字符串:

isNaN( '你好,我是字符串' ) = isNaN(Number( '你好是我字符串' )) = isNaN(NaN) = true

4.空对象:

isNaN({}) = isNaN(Number({})) = isNaN(NaN) = true

5.空数组:

isNaN([]) = isNaN(Number([])) = isNaN(0) = false

6.有数字的数组:

isNaN([1]) = isNaN(Number([1])) = isNaN(1) = false
isNaN([0]) = isNaN(Number([0])) = isNaN(1) = false
isNaN([0]) = isNaN(Number(['字符'])) = isNaN(NaN) = true

7.null或者undefined:

isNaN(null) = isNaN(Number(null) = isNaN(0) = false;
isNaN(undefined) = isNaN(Number(undefined) = isNaN(NaN) = true;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值