Javascript variable / 'NaN' behaving weirdly

前端 未结 1 742
北恋
北恋 2020-12-22 02:23

I have a couple of textboxes, Which return javascript Number values if valid data is in the textboxes, otherwise NaN. I get this strange behavior.

相关标签:
1条回答
  • 2020-12-22 02:48

    NaN is not equal to anything, not even NaN.

    Reference at MDN

    More detailed SO question and answer

    For the authoritative source, see the ECMAScript 5 Official Specification, sections 11.9.1 and 11.9.3:

    1. If Type(x) is the same as Type(y), then
         [...]
      c. If Type(x) is Number, then
         i. If x is NaN, return false.
        ii. If y is NaN, return false.
            [...]
    
    0 讨论(0)
提交回复
热议问题