Skip to content

Try our new Crash Courses!

Become a member using the button below to hide this banner and gain access to our new Crash Courses.

NaN – JavaScript

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.

References

NaN on MDN

Back to: JavaScript Reference > JS Data Types