[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/NaN [Back]  [Original]

NaN - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

NaN

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

NaN Not-A-Number( ) .

In this article

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

console.log(sanitize("1"));
// Expected output: "1"

console.log(sanitize("NotANumber"));
// Expected output: NaN

Number.NaN .

Property attributes of NaN

NaN . .

NaN , . .

NaN .

  • (: parseInt("blabla"), Number(undefined) Math.abs(undefined) )
  • (: Math.sqrt(-1))
  • (: 0 * Infinity, 1 ** Infinity, Infinity / Infinity, Infinity - Infinity)
  • NaN NaN (: 7 ** NaN, 7 * "blabla") - NaN .
  • (: new Date("blabla").getTime(), "".charCodeAt(1))

NaN NaN JavaScript . (NaN !== NaN ) IEEE 754 . NaN .

NaN JavaScript falsy .

NaN

NaN , Number.isNaN() isNaN() NaN . NaN x !== x .

js
NaN === NaN; // false
Number.NaN === NaN; // false
isNaN(NaN); // true
isNaN(Number.NaN); // true

function valueIsNaN(v) {
  return v !== v;
}
valueIsNaN(1); // false
valueIsNaN(NaN); // true
valueIsNaN(Number.NaN); // true

isNaN() Number.isNaN() . isNaN NaN, NaN , Number.isNaN NaN .

js
isNaN("hello world"); // true
Number.isNaN("hello world"); // false

BigInt Number.isNaN() isNaN() .

js
isNaN(1n); // TypeError: Conversion from 'BigInt' to 'number' is not allowed.
Number.isNaN(1n); // false

NaN . , (indexOf(), lastIndexOf()) NaN , includes() .

js
const arr = [2, 4, NaN, 12];
arr.indexOf(NaN); // -1
arr.includes(NaN); // true

//       NaN   .
arr.findIndex((n) => Number.isNaN(n)); // 2

NaN .

NaN

NaN . IEEE 754 0x7ff 0 NaN NaN. JavaScript typed arrays .

js
const f2b = (x) => new Uint8Array(new Float64Array([x]).buffer);
const b2f = (x) => new Float64Array(x.buffer)[0];
// NaN byte  .
const n = f2b(NaN);
//   NaN      .
n[0] = 1;
const nan2 = b2f(n);
console.log(nan2); // NaN
console.log(Object.is(nan2, NaN)); // true
console.log(f2b(NaN)); // Uint8Array(8) [0, 0, 0, 0, 0, 0, 248, 127]
console.log(f2b(nan2)); // Uint8Array(8) [1, 0, 0, 0, 0, 0, 248, 127]

NaN

NaN NaN . NaN 0 . 1 .

js
NaN ** 0 === 1; // true

Specification
ECMAScript 2027 LanguageSpecification
# sec-value-properties-of-the-global-object-nan


Web Proxy Viewer  |  New URL  |  Original Page