+ 3

What is NaN?

JavaScript

23rd Apr 2017, 4:16 PM
Manuel Rucker
Manuel Rucker - avatar
5 Answers
+ 11
It is a JavaScript value which results from nonsensical operations. Example: 0 / 0 or a number divided by a string or vice versa in which the string can't be coerced to a number. It also worth to note that, NaN is the only value or type that even yields false when compared to itself. e.g NaN == NaN. // false NaN === NaN // false
23rd Apr 2017, 4:22 PM
Benneth Yankey
Benneth Yankey - avatar
+ 17
NaN is "Not a Number". 5/'d' = NaN 'd'/6 = NaN Type of NaN is a number (funny though). NaN is a falsely value. Javascript return NaN if it couldn't convert something to a number or that thing isn't a number itself.
23rd Apr 2017, 4:18 PM
Wisdom Abioye
Wisdom Abioye - avatar
+ 14
@Ben Bright, is NaN the only type that yield false when compared to itself? What of this: obj1 = {}; obj2 = {}; obj1 == obj2; // false
23rd Apr 2017, 6:37 PM
Wisdom Abioye
Wisdom Abioye - avatar
+ 9
@Wisdom I said so because contents of objects are compared by references. And every single created object has a different reference so even if you compare the same objects it yields false.
23rd Apr 2017, 6:43 PM
Benneth Yankey
Benneth Yankey - avatar
0
Nan = Not A Number
23rd Apr 2017, 6:33 PM
Hayk