3 ms·
Unfortunately "not a number" is typeof "number" "number" === typeof NaN Returns true.
by madeofpalk 5y ago
Unfortunately "not a number" is typeof "number"
"number" === typeof NaN
Returns true.
- organsnyder 5y agoThat's a tricky one that I think would depend on use case. Yes, of course NaN isn't a number, but it's still kind of a number, depending on context.
- ohgodplsno 5y agoNaN is a float according to IEEE754. All numbers in Javascript being floats, it makes sense that typeof NaN === "number". Now, the fact that IEEE754 is insane is something else, but JS does nothing wrong (aside from not having not-floats)
- Ginden 5y ago> Now, the fact that IEEE754 is insane is something else, but JS does nothing wrong (aside from not having not-floats) JS has BigInt - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- ohgodplsno 5y agoBigInt is relatively recent, all things considered. JS only having floats is a conception flaw.
- dragonwriter 5y agoI mean, it depends on context what “numbers” are acceptable. For an overly general solution: const allowNumbers = { all: () => true, notNaN: n => !Number.isNaN(n), finite: Number.isFinite, integer: Number.isInteger, smol: n => Math.abs(n) < Number.EPSILON, lorge: n => n > Number.MAX_SAFE_INTEGER || n < Number.MIN_SAFE_INTEGER, } function isNumber(n, allow = allowNumbers.all) { return ("number" === typeof n) && allow(n); }
- twic 5y agoThis isn't bad, but for maintainability, it should be split into at least nine packages.
- marshray 5y agoIn the type of things that Javascript considers 'numbers', it's a value used to indicate that it's not of the type of things that math considers 'numbers'.