Number.NaN

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Number.NaN 静的データプロパティは非数 (Not-A-Number) を表す値であり、NaN と同じです。NaN の動作についての詳しい情報は、グローバルプロパティの説明を参照してください。

試してみましょう

function clean(x) {
  // eslint-disable-next-line use-isnan
  if (x === Number.NaN) {
    // Can never be true
    return null;
  }
  if (isNaN(x)) {
    return 0;
  }
}

console.log(clean(Number.NaN));
// Expected output: 0

数値 NaN です。

Number.NaN のプロパティ属性
書込可能不可
列挙可能不可
設定可能不可

解説

NaNNumber の静的プロパティですので、数値のプロパティとしてではなく、常に Number.NaN として使用してください。

値が数値であるかどうかのチェック

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

仕様書

Specification
ECMAScript® 2025 Language Specification
# sec-number.nan

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
NaN

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報