🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to JavaScript Notes
Topic #99

JS NaN

In JavaScript, NaN is short for Not a Number.

NaN is a JavaScript number that is not a legal number.

Invalid Number Operations

You get NaN when JavaScript cannot calculate a number.

Example

let x = 100 / "Apple";

document.getElementById("demo").innerHTML = x;

NaN is a Number

The type of NaN is number.

This may look strange, but NaN belongs to the JavaScript number type.

Example

let x = NaN;

document.getElementById("demo").innerHTML = typeof x;

Numeric Strings

JavaScript tries to convert numeric strings to numbers in arithmetic operations.

Example

let x = 100 / "10";

document.getElementById("demo").innerHTML = x;

Note: The result is 10, because "10" is converted to the number 10.


Non-Numeric Strings

A non-numeric string cannot be converted to a number.

Example

let x = 100 / "Apple";

document.getElementById("demo").innerHTML = x;

Note: The result is NaN, because "Apple" cannot be converted to a number.


Using isNaN()

You can use the JavaScript function isNaN() to find out if a value is not a number.

Example

let x = 100 / "Apple";

document.getElementById("demo").innerHTML = isNaN(x);

NaN is Not Equal to Itself

NaN is the only JavaScript value that is not equal to itself.

Example

let x = NaN;

document.getElementById("demo").innerHTML = x == x;

To test for NaN, use isNaN().


NaN in Math

If you use NaN in a mathematical operation, the result will also be NaN.

Example

let x = NaN;

let y = 5;

document.getElementById("demo").innerHTML = x + y;

Note: NaN means Not a Number. But the type of NaN is number. Use isNaN() to check if a value is NaN.

Want to go beyond the notes?

Join CodingNow 2.0's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

JS NaN – FAQs

Quick answers about learning JS NaN in JavaScript.

This free note from CodingNow 2.0 explains JS NaN in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on CodingNow 2.0, including JS NaN, is 100% free with no signup required.
With focused practice, most students grasp JS NaN in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now