10
balte
6y

if you ever want to really fuck with someone's head, compare against NaN in JavaScript...

Comments
  • 3
    (it always returns true. always. whether you compare !== or == or whatever. it's literally always)
  • 3
  • 2
    Well, Javascript.
  • 2
    What about 1 === NaN? Can't test right now but that might return false.
  • 3
    We ask this in our interviews. And its always false not true. This is not just a JavaScript thing.
  • 2
    The NaN != NaN thing is defined so in the standard for floating point numbers (IEEE 754).
  • 1
    @Hammster ah dammit, you're right. i fucked up because my colleague used !==
  • 1
    well say if

    const a = 'asdaxaz'
    a == NaN

    in this case you are comparing string value with a NaN value rather then checking for NaN. So it is like saying

    a == 'string'
  • 1
    always use isNaN()
Add Comment