We support #BlackLivesMatters !
If you support us then follow us by clicking here and following us!

Javascript Operations that return NaN

Get support on JavaScript,jQuery, AJAX and other related technology.
Post Reply
admin
Site Admin
Posts: 44

Javascript Operations that return NaN

Post by admin » Sun Oct 20, 2019 2:36 am

Mathematical operations on values other than numbers return NaN.

Code: Select all

"b" * 3
"cde" - "e"
[1, 2, 3] * 2
An exception: Single-number arrays.

Code: Select all

[2] * [3] // Returns 6
Also, remember that the + operator concatenates strings.

Code: Select all

"a" + "b" // Returns "ab"
Dividing zero by zero returns NaN.

Code: Select all

0 / 0 // NaN
Note: In mathematics generally (unlike in JavaScript programming), dividing by zero is not possible.

Post Reply