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.
Thuộc tính dữ liệu tĩnh Number.NaN biểu diễn Not-A-Number (Không phải số), tương đương với NaN. Để biết thêm thông tin về hành vi của NaN, xem mô tả cho thuộc tính toàn cục.
Try it
function clean(x) {
if (x === Number.NaN) {
// Can never be true
return null;
}
if (isNaN(x)) {
return 0;
}
}
console.log(clean(Number.NaN));
// Expected output: 0
Giá trị
Giá trị số NaN.
Property attributes of Number.NaN | |
|---|---|
| Writable | no |
| Enumerable | no |
| Configurable | no |
Mô tả
Vì NaN là thuộc tính tĩnh của Number, bạn luôn sử dụng nó là Number.NaN, thay vì là thuộc tính của một giá trị số.
Ví dụ
>Kiểm tra xem các giá trị có phải là số hay không
js
function sanitize(x) {
if (isNaN(x)) {
return Number.NaN;
}
return x;
}
Đặc tả
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-number.nan> |