Operations that return NaN

suggest change

Most 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents