Доброволците ни все още не са превели статията на Български. Присъединете се и помогнете да свършим тая работа!
Можете да прочетете статията и на English (US).

The Number.isNaN() method determines whether the passed value is NaN and its type is Number. It is a more robust version of the original, global isNaN().




The value to be tested for NaN.

Return value

true if the given value is NaN and its type is Number; otherwise, false.


Due to both equality operators, == and ===, evaluating to false when checking if NaN is NaN, the function Number.isNaN() has become necessary. This situation is unlike all other possible value comparisons in JavaScript.

In comparison to the global isNaN() function, Number.isNaN() doesn't suffer the problem of forcefully converting the parameter to a number. This means it is now safe to pass values that would normally convert to NaN, but aren't actually the same value as NaN. This also means that only values of the type number, that are also NaN, return true.


Number.isNaN(NaN);        // true
Number.isNaN(Number.NaN); // true
Number.isNaN(0 / 0);      // true

// e.g. these would have been true with global isNaN()
Number.isNaN('NaN');      // false
Number.isNaN(undefined);  // false
Number.isNaN({});         // false
Number.isNaN('blabla');   // false

// These all return false
Number.isNaN(' ');


The following works because NaN is the only value in javascript which is not equal to itself.

Number.isNaN = Number.isNaN || function(value) {     
    return value !== value;


Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Number.isnan' in that specification.
Standard Initial definition.
ECMAScript Latest Draft (ECMA-262)
The definition of 'Number.isnan' in that specification.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
isNaNChrome Full support 25Edge Full support 12Firefox Full support 15IE No support NoOpera Full support YesSafari Full support 9WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 15Opera Android Full support YesSafari iOS Full support 9Samsung Internet Android Full support Yesnodejs Full support 0.10


Full support  
Full support
No support  
No support

See also

Етикети за документа и сътрудници

Последно обновяване от: mdnwebdocs-bot,