ForgeFrontend — Prepare, Practice, Crack
Secure checkout
Lifetime access
Instant Drive delivery
Free updates forever

Prepare · Practice · Crack

What is NaN and how do you check for it?

Quick answer

NaN ('Not a Number') is the result of an invalid numeric operation; it is the only value not equal to itself, so use Number.isNaN().

In detail

NaN appears from operations like `0/0` or `Number('abc')`. Famously `NaN === NaN` is false, so you can't test equality. Use `Number.isNaN(x)` (strict, no coercion) — prefer it over the global `isNaN()`, which coerces and reports true for things like `isNaN('abc')`.

0 / 0;              // NaN
NaN === NaN;         // false
Number.isNaN(NaN);   // true
isNaN("abc");        // true  (coerces — avoid)
Number.isNaN("abc"); // false (no coercion)

Why interviewers ask this: A classic gotcha about value identity.

This is 1 of 118+ questions in the JavaScript Interview Kit

Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.

⚡ Get the JavaScript Interview Kit → ₹299

Full kit

JavaScript Interview Kit · ₹299

Get it →