Number.isNaN Redirect 1

This is an experimental technology, part of the Harmony (ECMAScript 6) proposal.
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future version of browsers as the spec changes.

Summary

The Number.isNaN() method determines whether the passed value is NaN. More robust version of the original global isNaN.

Syntax

Number.isNaN(testValue)

Parameters

testValue
The value to be tested for NaN.

Description

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.

Examples

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

// everything else: false
Number.isNaN(undefined);
Number.isNaN({});     

Number.isNaN(true);
Number.isNaN(null);
Number.isNaN(37);

Number.isNaN("37");
Number.isNaN("37.37");
Number.isNaN("");
Number.isNaN(" ");
Number.isNaN("NaN");
Number.isNaN("blabla"); // e.g. this would have been true with isNaN

Specifications

Specification Status Comment

ECMAScript Language Specification 6th Edition (ECMA-262)

Draft Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 25.0 15 (15) Not supported Not supported Not supported
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support Not supported ? 15.0 (15) Not supported Not supported Not supported

See also

  • The Number object it belongs to.

Document Tags and Contributors

 Contributors to this page: Sheppy
 Last updated by: Sheppy,