What is the difference between (NaN != NaN) and (NaN !== NaN)?

前端 未结 5 1041
旧时难觅i
旧时难觅i 2020-12-12 13:32

First of all I want to mention that I know how isNaN() and Number.isNaN() work. I am reading The Definite Guide by David Flanagan and he g

5条回答
  •  既然无缘
    2020-12-12 13:41

    For purposes of NaN, != and !== do the same thing.

    However, many programmers avoid == or != in JavaScript. For example, Douglas Crockford considers them among the "bad parts" of the JavaScript language because they behave in unexpected and confusing ways:

    JavaScript has two sets of equality operators: === and !==, and their evil twins == and !=. The good ones work the way you would expect.

    ...My advice is to never use the evil twins. Instead, always use === and !==.

提交回复
热议问题