Interview answer drill

Use this JavaScript interview question to rehearse a quick answer, common mistake, follow-up, and production pitfall.

What is the NaN property in JavaScript?Frontend interview answer

MediumEasyJavascript
Interview focus

This JavaScript interview question tests whether you can explain JavaScript NaN common mistakes: Number.isNaN, coercion traps, and validation bugs, connect it to production trade-offs, and handle common follow-up questions.

  • JavaScript NaN common mistakes: Number.isNaN, coercion traps, and validation bugs explanation without falling back to memorized docs wording
  • Global Object and Isnan reasoning, edge cases, and production failure modes
  • How you would answer the most likely JavaScript interview follow-up
Practice more JavaScript interview questions
Interview quick answer

NaN matters in production numeric validation because it is the only JavaScript value not equal to itself, global isNaN coerces inputs, and empty strings or malformed payloads create common mistake cases.

Full interview answer

Common mistake

NaN is not just a trivia definition. It is a production validation pitfall because NaN !== NaN, global isNaN coerces values, and empty strings or bad payloads can silently turn checks into bugs. The safer debugging rule is usually Number.isNaN.

JAVASCRIPT
console.log(0 / 0);         // NaN
console.log(parseInt('Hi'));  // NaN
console.log(Math.sqrt(-1));   // NaN
                  

Property

Description

Example

Type

The type of NaN is actually number.

typeof NaN // 'number'

Equality

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

NaN === NaN // false

Check

Use Number.isNaN() to check if a value is truly NaN.

Number.isNaN(NaN) // true

Key characteristics of NaN in JavaScript.

Why not just 'isNaN'?

The global isNaN() function tries to coerce values before checking, which can give confusing results. Always prefer Number.isNaN() because it doesn’t perform type coercion.

JAVASCRIPT
isNaN('Hello');         // true ❌ (string coerced)
Number.isNaN('Hello');   // false ✅
                  

Practical scenario
A numeric input can return '' or 'foo'; you need to detect NaN before calculations.


Common pitfalls

  • Using global isNaN, which coerces values.
  • Assuming NaN === NaN is true.
  • Mixing parseInt and Number without checks.
Trade-off or test tip
Prefer Number.isNaN for accuracy. Test empty strings, null, and non-numeric inputs.

Still so complicated?

Think of NaN like a 'broken calculator' output — the operation ran, but the result doesn’t make mathematical sense, so JavaScript gives you NaN instead of crashing.

Summary
  • NaN represents 'Not-a-Number' but its type is actually number.
  • It results from invalid numeric operations.
  • It’s the only value in JS that is not equal to itself.
  • Use Number.isNaN() instead of isNaN() to check safely.
Similar questions
Guides
Preparing for interviews?

Use this as one explanation rep, then continue with the JavaScript interview questions cluster or a guided prep path.