JavaScript Number NaN Property

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

What You’ll Learn

Number.NaN is a static data property on Number (same API as MDN Number.NaN). It is the Not-A-Number value — the same as global NaN. You get it from invalid math or failed numeric conversion. The gotcha beginners hit first: x === Number.NaN is never true. This tutorial covers detection with Number.isNaN, MDN patterns, five examples, and try-it labs.

01

Kind

Static property

02

Value

NaN

03

Same as

global NaN

04

Equals self?

Never

05

Writable

No

06

Baseline

Everywhere

Introduction

IEEE-754 floating point includes a special value for results that are not a number — for example 0 / 0 or Math.sqrt(-1). JavaScript exposes that value as both NaN and Number.NaN.

They are the same Not-A-Number value (Object.is(Number.NaN, NaN) is true), but === still returns false because NaN is not equal to anything, including itself. Prefer Number.isNaN(x) to test for it.

💡
Static Property

Static properties belong to Number itself. Always write Number.NaN. There is no (5).NaN, and you do not call it like a function.

This page is part of JavaScript Number Properties. Related tools include Number.isNaN(), Number.isFinite(), and Number.POSITIVE_INFINITY.

Understanding the NaN Property

NaN is still a typeof "number" — it is a special floating-point bit pattern, not a string or an error object. Once a calculation becomes NaN, more math usually stays NaN (poisoning).

  • It is a constant number, not a method.
  • Same value as global NaN (Object.is).
  • Number.NaN === Number.NaN is always false.
  • Detect with Number.isNaN(x) (preferred) or Object.is(x, NaN).

📝 Syntax

General form of the static property Number.NaN:

JavaScript
Number.NaN

Value

The number value NaN (Not-A-Number) — same as the global NaN property.

Property attributes

AttributeValue
Writablefalse
Enumerablefalse
Configurablefalse

Common patterns

JavaScript
Number.NaN;                         // NaN
Object.is(Number.NaN, NaN);         // true
Number.NaN === Number.NaN;          // false  ← never equals itself
Number.isNaN(Number.NaN);           // true

0 / 0;                              // NaN
Infinity - Infinity;                // NaN
Math.sqrt(-1);                      // NaN
Number("abc");                      // NaN

function sanitize(x) {
  if (Number.isNaN(x)) {
    return Number.NaN;
  }
  return x;
}

⚡ Quick Reference

GoalCode
Read Not-A-NumberNumber.NaN
Same as global?Object.is(Number.NaN, NaN)
Detect NaN (safe)Number.isNaN(x)
Never do thisx === Number.NaN (always false)
Indeterminate math0 / 0NaN
Failed conversionNumber("abc")NaN

🔍 At a Glance

Four facts to remember about Number.NaN.

Kind
static

Property on Number

Value
NaN

Same as global NaN

=== self?
false

Use Number.isNaN

Mutable
no

Read-only constant

📋 Number.isNaN vs isNaN vs === Number.NaN

Number.isNaN(x)isNaN(x)x === Number.NaN
NaNtruetruefalse
"foo"falsetrue (coerces)false
undefinedfalsetruefalse
42falsefalsefalse
Best for?Real NaN onlyLoose “not numeric”Never use

Examples Gallery

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

📚 Getting Started

Read the constant and see why strict equality fails.

Example 1 — Read Number.NaN

Confirm it is the same Not-A-Number as global NaN.

JavaScript
Number.NaN;
Object.is(Number.NaN, NaN);   // true
typeof Number.NaN;            // "number"
Try It Yourself

How It Works

Object.is compares by SameValue, so it treats both forms of NaN as identical. typeof still reports "number".

Example 2 — Why === Number.NaN Fails

The classic beginner trap — NaN is never equal to itself.

JavaScript
Number.NaN === Number.NaN;    // false
Number.NaN === NaN;           // false
Number.isNaN(Number.NaN);     // true
Object.is(Number.NaN, NaN);   // true
Try It Yourself

How It Works

IEEE-754 requires NaN ≠ NaN. Always detect with Number.isNaN() (or Object.is), never with ===.

📈 Practical Patterns

MDN-style checks, common sources, and returning Number.NaN.

Example 3 — MDN clean() Trap

Comparing with === Number.NaN can never succeed — use isNaN / Number.isNaN.

JavaScript
function clean(x) {
  if (x === Number.NaN) {
    // Can never be true
    return null;
  }
  if (isNaN(x)) {
    return 0;
  }
  return x;
}

clean(Number.NaN);  // 0
Try It Yourself

How It Works

The first if is dead code. The second branch catches NaN (and other non-numeric values if you use global isNaN). Prefer Number.isNaN for NaN-only checks.

Example 4 — Common Ways to Get NaN

Invalid math and failed conversions all produce Not-A-Number.

JavaScript
0 / 0;                 // NaN
Infinity - Infinity;   // NaN
Math.sqrt(-1);         // NaN
Number("abc");         // NaN
parseFloat("xyz");     // NaN
Try It Yourself

How It Works

These are not exceptions — JavaScript returns NaN and continues. Check results before using them in further math.

Example 5 — MDN sanitize() Pattern

Return Number.NaN when a value is not numeric.

JavaScript
function sanitize(x) {
  if (isNaN(x)) {
    return Number.NaN;
  }
  return x;
}

sanitize(42);       // 42
sanitize("abc");    // NaN
Number.isNaN(sanitize("abc"));  // true
Try It Yourself

How It Works

MDN uses global isNaN so strings like "abc" are treated as non-numeric. Returning Number.NaN keeps the failure signal on the Number API. For NaN-only (no coercion), use Number.isNaN.

🚀 Common Use Cases

  • Failed conversion signal — return Number.NaN when parsing fails.
  • Invalid math marker — detect poisoned results after 0 / 0 style ops.
  • Input validation — reject bad numeric fields with Number.isNaN.
  • Sentinel values — some APIs use NaN to mean “unknown number”.
  • Teaching IEEE-754 — show that NaN ≠ NaN by design.
  • Pair with isFinite — reject NaN, Infinity, and -Infinity together.

🧠 How Values Become NaN

1

Start with invalid math or text

Divide zeros, subtract infinities, or convert non-numeric strings.

Input
2

No numeric result exists

IEEE-754 has no finite answer for that operation.

Limit
3

Produce NaN

The result becomes Number.NaN / global NaN.

Result
4

Detect with isNaN helpers

Never use === — use Number.isNaN or Object.is.

📝 Notes

  • This is a static property — use Number.NaN only.
  • Do not write Number.NaN() — it is not a function.
  • Number.NaN === Number.NaN is always false.
  • Object.is(Number.NaN, NaN) is true.
  • Prefer Number.isNaN() over global isNaN when you mean “is this NaN?”.
  • typeof NaN is "number" — surprising but correct.

Browser & Runtime Support

Number.NaN is Baseline Widely available and supported in every modern browser and Node.js.

Baseline · Widely available

Number.NaN

Safe for production everywhere. Same Not-A-Number value as global NaN, grouped under Number.

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.NaN Excellent

Bottom line: Use Number.NaN to name Not-A-Number. Detect with Number.isNaN — never with ===. Remember NaN never equals itself.

Conclusion

Number.NaN is the static constant for Not-A-Number — the value you get from invalid math and failed conversions, identical in value to global NaN.

Continue with Number() constructor, isNaN(), isFinite(), POSITIVE_INFINITY, or the Number properties hub.

💡 Best Practices

✅ Do

  • Read Number.NaN on the constructor
  • Detect with Number.isNaN(x)
  • Use Object.is(x, NaN) when you need SameValue
  • Return Number.NaN as an explicit failure signal
  • Pair with Number.isFinite for full non-finite checks

❌ Don’t

  • Write (5).NaN or call it as a function
  • Compare with x === Number.NaN (always false)
  • Assume typeof NaN is something other than "number"
  • Ignore that isNaN("foo") coerces and returns true
  • Forget NaN “poisons” further arithmetic

Key Takeaways

Knowledge Unlocked

Five things to remember about Number.NaN

Static name for IEEE-754 Not-A-Number.

5
Core concepts
NaN 02

Value

NaN

Constant
03

===

never

Trap
04

Check

isNaN

Validate
05

Mutable

no

Readonly

❓ Frequently Asked Questions

Number.NaN is the Not-A-Number value on Number. It is the same IEEE-754 NaN as the global NaN. Example sources: 0 / 0, Infinity - Infinity, Math.sqrt(-1), and Number("abc").
Yes. Read it on Number itself: Number.NaN. There is no (5).NaN on number instances, and it is not a method.
NaN is the only JavaScript value that is not equal to itself. Number.NaN === Number.NaN and Number.NaN === NaN are both false. Use Number.isNaN(x) or Object.is(x, NaN).
Prefer Number.isNaN(x). It returns true only for actual NaN. Global isNaN(x) coerces first, so isNaN("foo") is true even though "foo" is a string.
Yes — same Not-A-Number value. Object.is(Number.NaN, NaN) is true. Prefer Number.NaN when you want the constant grouped with other Number properties.
It is Baseline Widely available and supported in every modern browser and Node.js.
Did you know?

NaN is the only JavaScript value where x !== x is true. That is why some older code used x !== x as a NaN check — today, prefer Number.isNaN(x).

More Number Properties

Return to the hub for static Number constants.

Number properties 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