JavaScript: The Definitive Guide
24.93. isNaN( ): check for not-a-number
ECMAScript v1
24.93.1. Synopsis
isNaN(x) 24.93.1.1. Arguments
24.93.1.2. Returns
true if x is (or can be converted to) the special not-a-number value; false if x is any other value. 24.93.2. Description
isNaN( ) tests its argument to determine whether it is the value NaN, which represents an illegal number (such as the result of division by zero). This function is required because comparing a NaN with any value, including itself, always returns false, so it is not possible to test for NaN with the == or === operators. A common use of isNaN( ) is to test the results of parseFloat( ) and parseInt( ) to determine if they represent legal numbers. You can also use isNaN( ) to check for arithmetic errors, such as division by zero. 24.93.3. Example
isNaN(0); // Returns false isNaN(0/0); // Returns true isNaN(parseInt("3")); // Returns false isNaN(parseInt("hello")); // Returns true isNaN("3"); // Returns false isNaN("hello"); // Returns true isNaN(true); // Returns false isNaN(undefined); // Returns true
24.93.4. See Also
isFinite( ), NaN, Number.NaN, parseFloat( ), parseInt( ) |
Категории