weijiyang / GOOD-IDEA

这里记录一些灵感~详见ISSUES
1 stars 0 forks source link

判断NaN #5

Open weijiyang opened 5 years ago

weijiyang commented 5 years ago

如何判断NaN

  1. 利用 NaN !== NaN
    let arr = NaN 
    if (arr !== arr){ console.log('值为NaN')}
  2. 利用isNaN 有些小伙伴可能就这么写了
    let arr = NaN
    if(isNaN(arr)) { console.log('值为NaN')}

    但是你有没有考虑过如果是字符串呢? 下面几种情况说明上面的问题

image