11

typeof NaN === typeof NaN //false

Why?

Comments
  • 0
    @bigus-dickus typeof NaN returns Number as string then why two string cannot pass equality check for type and value
  • 0
    @bigus-dickus thanks bud will look into this
  • 2
    @GAGANDEEPP @bigus-dickus typeof NaN returns 'number'. This statement should be true. But nobody stops you from defining the 'NaN' variable, just like nobody stops you to re-define 'undefined'.
    For NaN, it's safer to use isNaN()
    For undefined, it's safer to use void 0
  • 4
    @sunfishcc safest method of all is to not use JavaScript
  • 1
    @RememberMe boom... no js. DevRant is down. You can’t post anymore 😈
  • 1
    @sunfishcc I meant, maybe use a language that compiles down to js so that you don't shoot yourself in the foot
    Like Typescript, Elm, Purescript, etc.
  • 0
    @RememberMe I use typescript with React. But not in NodeJs. Don’t like the extra generated code.
    Typescript allows you to cast any as anything. So it doesn’t help if you try to format an arbitrary value as number. Test NaN is still required.
    BTW, NaN is also in python. It’s part of the floating point system.
  • 0
    I'll explain: the song goes like this...

    NaN NaN NaN NaN
    NaN NaN NaN NaN

    BATMAN!!!
Add Comment