4

typeof NaN
'number'

Yes... in JavaScript, the type of NaN is Number. Go figure...

Comments
  • 7
    Tbf, it’s not JS's fault.
    NaN is a float and floats are numbers.
  • 5
    That’s why isNaN exists 😂

    Though you have to check that it’s a number first or you end up with false positives if you’re dealing with things that can’t be coerced into being numbers.
  • 4
    @Lensflare Whatever floats your boat. jk lol
  • 2
    @AmyShackles Yes, my webdev skills are rusty. I'm slowly picking up on them again.
  • 6
    Been a while but I always used to use (n == n), if that resolves to false then it's NaN. Not that this makes anything saner.
  • 3
    @CaptainRant You’ll get there. You’ve got this. ❤️
  • 4
    @MM83 so not a number is not not a number?
  • 3
    @MM83 I simultaneously admire and dislike that approach.
  • 3
    @donkulator sometimes horrible things are weirdly fascinating.
  • 2
    @Lensflare Fuck lol. Now I'm thinking of nyan cat.
  • 3
    @donkulator same, it feels wrong typing it out
  • 5
    @Lensflare that not a number is not not a number is one of the few immutable truths you can rely on with JS.
  • 3
    @MM83 wtf.. This begs for a util.js and an isNaN() inside. And whatever twisted magic it takes -- encapsulate it there, out of anyone's sight
  • 3
    @MM83 unless it’s actually not a number and not not a number (NaN)
  • 1
  • 2
    @netikras absolutely. If there's one thing the JS community needs, its another library of wrapper functions for native methods.
  • 1
    @Lensflare perhaps we should lobby whichever chimp enclosure maintains the typescript spec to add the nNaN type, for clarity in these situations.
  • 1
    JavaScript getting heat for this is always so funny because it's a gateway drug to floating point encoding (which is a HELLSCAPE)

    Surprise, here's the exact same thing in c (a function which returns NaN, which is a double)

    Here's some homework for you: check out how infinity and negative infinity work too!
  • 1
    @MM83 @Lensflare introducing: isaN!

    const isaN = num => !isNaN(num);

    It will be available via NPM soon through a microservice that costs 2.99 a month and makes calls to

    GET https://api.isan.io/v4/isan?n=x

    Rate limited to 1000/day per key, of course, unless you purchase the enterprise subscription which costs $45 / seat / month and you're locked into a 2 year contract (the service will go out of business before your contract finishes)
  • 0
    @AlgoRythm wait till they find out there are multiple types of NaNs ;P
Add Comment