JavaScript Number isNaN() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Static method

What You’ll Learn

Number.isNaN() is a static method on Number (same API as MDN Number.isNaN). Call Number.isNaN(value) — not on a number instance. It returns true only for the number value NaN. This tutorial covers syntax, why === fails, the difference from global isNaN(), five examples, and try-it labs.

01

Call on

Number only

02

Returns

boolean

03

True when

Number NaN

04

False for

Non-numbers

05

Coercion

None

06

Baseline

Everywhere

Introduction

Failed math and bad parses often produce NaN (“Not a Number”). You cannot detect it with x === NaN, because NaN is not equal to itself.

Number.isNaN() is the reliable, modern check. Unlike the older global isNaN(), it does not coerce strings first — so Number.isNaN("NaN") is false.

💡
Static Method

Static methods belong to Number itself. Always write Number.isNaN(x). There is no (5).isNaN() on Number.prototype.

This page is part of JavaScript Number Methods. Related static checks include Number.isFinite() and Number.isInteger().

Understanding the isNaN() Method

Pass any value to Number.isNaN(value). You get true only when both of these are true:

  • The type is "number".
  • The value is NaN (including Number.NaN and results like 0 / 0).

Everything else — strings, objects, undefined, normal numbers — returns false. That strictness is why it is safer than global isNaN().

📝 Syntax

General form of the static method Number.isNaN:

JavaScript
Number.isNaN(value)

Parameters

  • value (any) — the value to test for being the number NaN.

Return value

A boolean:

ValueReturns
NaN / Number.NaN / 0 / 0true
Normal number (e.g. 37)false
Non-number (e.g. "NaN", undefined)false
Infinityfalse (infinite, but not NaN)

Exceptions

  • None for normal calls — invalid types simply return false.

Common patterns

JavaScript
Number.isNaN(NaN);           // true
Number.isNaN(0 / 0);         // true
Number.isNaN(37);            // false
Number.isNaN("NaN");         // false
isNaN("NaN");                // true (global — coerces!)
NaN === NaN;                 // false (never use ===)

⚡ Quick Reference

GoalCode
Safe NaN checkNumber.isNaN(x)
After parseNumber.isNaN(Number(s))
Reject bad mathNumber.isNaN(0 / 0)true
Do not usex === NaN (always false)
Avoid coercion surprisesPrefer Number.isNaN over global isNaN
Readable alternativex !== x (true only for NaN)

🔍 At a Glance

Four facts to remember about Number.isNaN().

Kind
static

Call on Number, not instances

Returns
boolean

true only for number NaN

Coercion
none

Unlike global isNaN()

Support
Baseline

ES2015+ everywhere modern

📋 Number.isNaN() vs global isNaN()

Number.isNaN(x)isNaN(x)
Coerces first?NoYes (ToNumber)
NaNtruetrue
"NaN"falsetrue
undefinedfalsetrue
"37"falsefalse (becomes 37)
Best forStrict type-safe checksLegacy / coerced input

Examples Gallery

Examples follow MDN patterns. Use View Output or Try It Yourself for each case.

📚 Getting Started

Detect NaN from literals and failed math.

Example 1 — The NaN Value

The literal NaN is a number value that fails equality with itself.

JavaScript
Number.isNaN(NaN);  // true
Try It Yourself

How It Works

NaN has type "number" and is the NaN value, so the check returns true. Remember: NaN === NaN is still false.

Example 2 — Invalid Division

0 / 0 is a common way NaN appears in real code.

JavaScript
Number.isNaN(0 / 0);  // true
Try It Yourself

How It Works

Indeterminate forms like 0 / 0 evaluate to NaN. Guard calculations before you format or store the result.

📈 Practical Patterns

Normal numbers, non-numbers, and Number.NaN.

Example 3 — Normal Number

Ordinary numbers are not NaN.

JavaScript
Number.isNaN(37);  // false
Try It Yourself

How It Works

37 is a finite number value, so Number.isNaN returns false.

Example 4 — No String Coercion

The string "NaN" is not the number NaN.

JavaScript
Number.isNaN("NaN");  // false
// isNaN("NaN");      // true (global coerces)
Try It Yourself

How It Works

Because there is no coercion, a string always fails. After parsing, Number.isNaN(Number("100F")) becomes true.

Example 5 — Number.NaN

The constant on Number is the same NaN value.

JavaScript
Number.isNaN(Number.NaN);  // true
Try It Yourself

How It Works

Number.NaN and the global NaN identifier refer to the same IEEE-754 NaN value.

🚀 Common Use Cases

  • Guard after parseNumber.isNaN(Number(raw)) before using form input.
  • Failed math — catch 0 / 0 and other indeterminate results.
  • API validation — reject NaN before JSON or database writes.
  • Replace === NaN — the only reliable equality-style check for NaN.
  • Safer than global isNaN — avoid treating strings/objects as NaN by accident.
  • Pair with isFinite — finite + not NaN is already covered by Number.isFinite.

🧠 How Number.isNaN() Decides

1

Receive value

Any JavaScript value can be passed in.

Input
2

Check type

Must be typeof number — no coercion.

Type
3

Detect NaN

Same idea as testing x !== x.

Filter
4

Return boolean

true only for the number NaN.

📝 Notes

  • This is a static method — use Number.isNaN(x) only.
  • Does not coerce strings, objects, undefined, or booleans.
  • NaN === NaN is always false — never use === to find NaN.
  • Global isNaN is older and coercing — prefer the Number static method in new code.
  • Number.isNaN(Infinity) is false — use Number.isFinite() for infinity checks.
  • Among all JS values, only NaN satisfies x !== x.

Browser & Runtime Support

Number.isNaN() is Baseline Widely available — part of ES2015 and supported in every modern browser and Node.js.

Baseline · Widely available

Number.isNaN()

Safe for production everywhere. Prefer it over global isNaN() for type-safe NaN detection.

100% Universal support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Number.isNaN() Excellent

Bottom line: Use Number.isNaN for new code. Parse strings yourself before checking if text input must become a number first.

Conclusion

Number.isNaN() is the modern, static way to detect the number value NaN — without the coercion surprises of global isNaN(), and without relying on broken === comparisons.

Continue with Number.isSafeInteger() for precision-safe integers, Number.isInteger() for any integer check, or return to the Number methods hub.

💡 Best Practices

✅ Do

  • Call Number.isNaN(x) on the constructor
  • Parse user text with Number(s) before checking
  • Prefer it over global isNaN in new code
  • Use it instead of x === NaN
  • Combine with finite/integer checks when validating inputs

❌ Don’t

  • Write (5).isNaN() — that is not a Number method
  • Assume the string "NaN" passes the check
  • Use === NaN for detection
  • Confuse NaN with Infinity
  • Rely on global isNaN(undefined) being true

Key Takeaways

Knowledge Unlocked

Five things to remember about Number.isNaN()

Static, strict, boolean check for the number NaN.

5
Core concepts
02

Returns

boolean

Result
03

Equality

NaN≠NaN

Quirk
Aa 04

Coercion

none

Strict
05

Safe

Baseline

Support

❓ Frequently Asked Questions

Number.isNaN(value) returns true only when value is of type number and is NaN. Example: Number.isNaN(NaN) is true; Number.isNaN("NaN") is false.
Yes. Call it on Number itself: Number.isNaN(x). Do not call it on a number instance like (5).isNaN() — that is not the Number API.
Global isNaN() coerces the argument to a number first, so isNaN("NaN") and isNaN(undefined) are true. Number.isNaN() never coerces — non-numbers always return false.
In JavaScript, NaN is the only value that is not equal to itself. NaN === NaN is false. Use Number.isNaN(x) (or the less readable x !== x) instead.
Yes. 0 / 0 evaluates to NaN, and that value is a number, so Number.isNaN(0 / 0) is true.
It is Baseline Widely available (ES2015) and supported in every modern browser and Node.js.
Did you know?

Among all possible JavaScript values, only NaN makes x !== x evaluate to true. That is why Number.isNaN(x) can be thought of as a readable wrapper around that test.

More Number Methods

Return to the hub for instance and static Number tutorials.

Number methods hub →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful