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 のプロパティ属性 | |
---|---|
書込可能 | 不可 |
列挙可能 | 不可 |
設定可能 | 不可 |
解説
NaN
は Number
の静的プロパティですので、数値のプロパティとしてではなく、常に 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 GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
NaN |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.