Operations that return NaN
suggest changeMost arithmetic operators coerce their operands with ToNumber. When that coercion cannot produce a number, the result is NaN. + is different: if either operand becomes a string, it concatenates.
"a" + 1 // "a1"
"b" * 3 // NaN
"cde" - "e" // NaN
[1, 2, 3] * 2 // NaN
An exception: Single-number arrays.
[2] * [3] // Returns 6
Also, remember that the + operator concatenates strings.
"a" + "b" // Returns "ab"
Dividing zero by zero returns NaN.
0 / 0 // NaN
Note: a non-zero number divided by zero is Infinity or -Infinity, not NaN. In mathematics, dividing by zero is not defined.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents