9 AnswersNew Answer
I could be wrong but I believe it belongs to the Number class which makes it a number type, but not an actual number
Maybe it's like saying that a human is an animal that is not an animal. Humans belong to the category of animals but are not technically called animals. I don't know if that analogy is good.
Math operations involve numeric value(s) as inputs yielding a numeric return value. Example: 10 / 2 returns 5 operation: division (/) inputs: 10 and 2 output: 5 In situations where the inputs can cause an invalid math operation, such as dividing by zero or evaluating the square root of a negative number, it will not be possible to yield a numeric value. Typically, invalid math operations would simply cause an exception. However, a placeholder value (NaN) could be used to indicate the result of an invalid math operation while preserving the type of the value as a number. ---- Simply restated, NaN is a placeholder value for number type variables that represent the result of an invalid math operation as an alternative to throwing an exception.
According to its definition, NaN is number that reperesents undefined or unrepresentable number. From what I know, NaN is something like "special value", or an error flag, when the result of a calculation is undefined, like 0/0 or square root of negative one. So NaN is a number that is used to represent undefined number
Younes BOUDOUL Interesting way to explain NaN. 😉 However, I'd say that NaN is ALWAYS a value of type Number that ALWAYS represents a value that is, eh hem... well... "Not a Number." 🤓
you are right!! but sometimes NaN appear as a number ad that's why. for example when you type 3.235785684 * 11e512 he returns Infinity that's make infinity a number for JS But when you type (3.235785684 * 11e512)/(3.235785684 * 11e512) he should be returns 1 like 2/2 but he returns NaN if we realize it with the same logic as we did with infinity!! we should say NaN is an number BUT one of the most characters of numbers is order 0 => 1 => ...=> 999 ... & NaN is unordered: NaN < 1; // false // so he is a number sometimes and not a number in other cases