但如果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;