Resum
La propietat global NaN
és un valor que representa Not-A-Number.
Property attributes of NaN |
|
---|---|
Writable | no |
Enumerable | no |
Configurable | no |
Sintaxi
NaN
Descripció
NaN
és una propietat de l'objecte global.
El valor inicial de NaN
és Not-A-Number — el mateix que el valor de Number.NaN
. En navegadors moderns NaN
és una propietat no configurable que no pot ser escrita. En cas contrari es recomana no sobreescriure el seu valor.
L'ús directe de NaN
és poc freqüent. Apareix tot sovint però com va valor retornat quan una funció matemàtica falla (Math.sqrt(-1)
) o quan s'intenta convertir una cadena de text a nombre sense èxit (parseInt("blabla")
).
Comparant NaN
L'operador d'igualtat (==
i ===
) no pot ésser emprat per comparar un resultat amb NaN
. Es fa necessari l'ús de Number.isNaN()
o bé isNaN()
.
NaN === NaN; // false
Number.NaN === NaN; // false
isNaN(NaN); // true
isNaN(Number.NaN); // true
Especificacions
Especificació | Estat | Comentaris |
---|---|---|
ECMAScript 1a Edició. | Standard | Definició inicial. Implementat a JavaScript 1.3 |
ECMAScript 5.1 (ECMA-262) The definition of 'NaN' in that specification. |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'NaN' in that specification. |
Standard |
Compatibilitat amb navegadors
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Suport bàsic | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Característica | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Suport bàsic | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |