Tutorial by Examples

Mathematical operations on values other than numbers return NaN. "a" + 1 "b" * 3 "cde" - "e" [1, 2, 3] * 2 An exception: Single-number arrays. [2] * [3] // Returns 6 Also, remember that the + operator concatenates strings. "a" + "b&...
Generally, Math functions that are given non-numeric arguments will return NaN. Math.floor("a") The square root of a negative number returns NaN, because Math.sqrt does not support imaginary or complex numbers. Math.sqrt(-1)
window.isNaN() The global function isNaN() can be used to check if a certain value or expression evaluates to NaN. This function (in short) first checks if the value is a number, if not tries to convert it (*), and then checks if the resulting value is NaN. For this reason, this testing method may ...
null is used for representing the intentional absence of an object value and is a primitive value. Unlike undefined, it is not a property of the global object. It is equal to undefined but not identical to it. null == undefined; // true null === undefined; // false CAREFUL: The typeof null i...
At first glance it may appear that null and undefined are basically the same, however there are subtle but important differences. undefined is the absence of a value in the compiler, because where it should be a value, there hasn't been put one, like the case of an unassigned variable. undefined...
1 / 0; // Infinity // Wait! WHAAAT? Infinity is a property of the global object (therefore a global variable) that represents mathematical infinity. It is a reference to Number.POSITIVE_INFINITY It is greater than any other value, and you can get it by dividing by 0 or by evaluating the express...

NaN

NaN stands for "Not a Number." When a mathematical function or operation in JavaScript cannot return a specific number, it returns the value NaN instead. It is a property of the global object, and a reference to Number.NaN window.hasOwnProperty('NaN'); // true NaN; // NaN Perhaps con...
The Number constructor has some built in constants that can be useful Number.MAX_VALUE; // 1.7976931348623157e+308 Number.MAX_SAFE_INTEGER; // 9007199254740991 Number.MIN_VALUE; // 5e-324 Number.MIN_SAFE_INTEGER; // -9007199254740991 Number.EPSILON; // 0.000...

Page 1 of 1