| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/NaN | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
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( ) .
function sanitize(x) {
if (isNaN(x)) {
return NaN;
}
return x;
}
console.log(sanitize("1"));
// Expected output: "1"
console.log(sanitize("NotANumber"));
// Expected output: 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 ( ) NaN . ( counter-example )NaN (>, <, >=, <=) false.NaN ( ==, !=, === !== ) NaN .NaN JavaScript falsy .
NaN NaN , Number.isNaN() isNaN() NaN . NaN x !== x .
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 .
isNaN("hello world"); // true
Number.isNaN("hello world"); // false
BigInt Number.isNaN() isNaN() .
isNaN(1n); // TypeError: Conversion from 'BigInt' to 'number' is not allowed.
Number.isNaN(1n); // false
NaN . , (indexOf(), lastIndexOf()) NaN , includes() .
const arr = [2, 4, NaN, 12];
arr.indexOf(NaN); // -1
arr.includes(NaN); // true
// NaN .
arr.findIndex((n) => Number.isNaN(n)); // 2
NaN . IEEE 754 0x7ff 0 NaN NaN. JavaScript typed arrays .
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 ** 0 === 1; // true
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-value-properties-of-the-global-object-nan |
This page was last modified on 2026 7 15 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |