Summary
Details
If you try to perform a mathematical operation (except addition) on something that’s not a number (like a string or array), you will get NaN
as a result. NaN
means Not-A-Number. For example, trying to divide a string will result in NaN
, like this:
'hello world' / 2
// result: NaN
The exception is addition. If you try to add a string and a number, the number will be converted into a string and the two strings will be combined (or concatenated), like this:
'hello world' + 2
// result: 'hello world2'
Demo
Exercises
Try the following statements in the console:
'hello world' / 2
The answer should be NaN
.