1、isNaN(val)
通过Number()强制类型转换 将val转成number类型,再判断是否为NaN
So isNaN()是判断val是否能转为数字
console.log(isNaN(null)); //false
console.log(isNaN(true)); //false
console.log(isNaN(false)); //false
console.log(isNaN(0)); //false
console.log(isNaN(undefined)); //true
console.log(isNaN("AB")); //true
console.log(isNaN({a: 1})); //true
console.log(isNaN(NaN)); //true
2、Number.isNaN()
Es6 新加的严格判断是否===NaN
console.log(Number.isNaN(null)); //false
console.log(Number.isNaN(true)); //false
console.log(Number.isNaN(false)); //false
console.log(Number.isNaN(0)); //false
console.log(Number.isNaN(undefined)); //false
console.log(Number.isNaN("AB")); //false
console.log(Number.isNaN({a: 1})); //false
console.log(Number.isNaN(NaN)); //true