in es6 you can use
const x = 0 / 0 ; // NaN Object.is(x, NaN) ; // true
NaN property represents a value that is “not a number”. This special value results from an operation that could not be performed either because one of the operands was non-numeric (e.g.,
"abc" / 4), or because the result of the operation is non-numeric.
While this seems straightforward enough, there are a couple of somewhat surprising characteristics of
NaN that can result in hair-pulling bugs if one is not aware of them.
For one thing, although
NaN means “not a number”, its type is, believe it or not, Number:
console.log(typeof NaN === "number"); // logs "true"
NaN compared to anything – even itself! – is false:
console.log(NaN === NaN); // logs "false"
A semi-reliable way to test whether a number is equal to NaN is with the built-in function
isNaN(), but even using
isNaN() is an imperfect solution.
A better solution would either be to use
value !== value, which would only produce true if the value is equal to NaN. Also, ES6 offers a new
Number.isNaN() function, which is a different and more reliable than the old global isNaN() function.
- 1How can I filter questions by programming language in Stack Dev?
- 1Can't add AMP Variable for Google Tag Manager
- 5How can I rename git local and remote branch name?
- 1How can I transition height: 0; to height: auto; using CSS?
- 2How can i write update query in SQL
- 3Where can I get some?
- 1Can't run flutter project: No connected device
- 2How can I remove the debug banner in right top corner ?
- 4How can i use inheritance in c#
- 5How do you vertically align texts in CSS?