Os nossos voluntários ainda não traduziram este artigo para Português (Europeu). Ajude-nos a concluir o trabalho!
Pode também ler o artigo em English (US).

The global NaN property is a value representing Not-A-Number.

Property attributes of NaN
Writable no
Enumerable no
Configurable no




NaN is a property of the global object.

The initial value of NaN is Not-A-Number — the same as the value of Number.NaN. In modern browsers, NaN is a non-configurable, non-writable property. Even when this is not the case, avoid overriding it.

It is rather rare to use NaN in a program. It is the returned value when Math functions fail (Math.sqrt(-1)) or when a function trying to parse a number fails (parseInt("blabla")).

Testing against NaN

NaN compares unequal (via ==, !=, ===, and !==) to any other value -- including to another NaN value.  Use Number.isNaN() or isNaN() to most clearly determine whether a value is NaN.  Or perform a self-comparison: NaN, and only NaN, will compare unequal to itself.

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


Specification Status Comment
ECMAScript 1st Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.3
ECMAScript 5.1 (ECMA-262)
The definition of 'NaN' in that specification.
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'NaN' in that specification.
ECMAScript Latest Draft (ECMA-262)
The definition of 'NaN' in that specification.
Living Standard  

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic Support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic Support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

See also

Etiquetas do documento e contribuidores

 Última atualização por: fscholz,