Is NaN falsy? Why NaN === false returns false

前端 未结 7 839
走了就别回头了
走了就别回头了 2020-12-13 18:43
  1. Why NaN === false => false, isn\'t NaN falsy?
  2. Why NaN === NaN => false, but !!NaN === !!NaN => true

I\'v

7条回答
  •  死守一世寂寞
    2020-12-13 19:33

    1. Falsy and being strictly equal to false are very different things, that's why one has a y instead of an e. ;)
    2. NaN is spec'd to never be equal to anything. The second part of your question is comparing false === false, which is funnily enough, true :)

    If you really want to know if something is NaN, you can use Object.is(). Running Object.is(NaN, NaN) returns true.

提交回复
热议问题