5 ms·
typeof x === 'number' && !Number.isNaN(x)
by frankincense 5y ago
typeof x === 'number' && !Number.isNaN(x)
- newsbinator 5y agoThis seems like the best solution. Any weird edge cases against this one?
- mirekrusin 5y ago+/- Infinity, better to use Number.isFinite.
- stagas 5y agoInfinities.
- JasonCannon 5y agoComparing it against the list of examples given in is-number, this solution does not properly handle numbers represented as strings, and it also recognizes Infinity as a number.
- TheCoelacanth 5y agoBecause strings aren't numbers and Infinity is a number
- JasonCannon 5y agoStrings are the safest way to hold big numbers in JavaScript due to how JavaScript represents numbers. Also no, infinity is not a number. It's a concept.
- boomlinde 5y agoNumbers is a concept. For some purposes it is useful to consider a number that is infinite, which is why concepts like the extended real number line have been invented.