| значение | typeof |
|---|---|
undefined |
"undefined" |
null |
"object" |
true or false |
"boolean" |
all numbers or NaN |
"number" |
| all strings | "string" |
| all symbols | "symbol" |
| all functions | "function" |
| all arrays | "object" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Number.isNaN = Number.isNaN || (function(value) { | |
| return value !== value; | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isNan(value) { | |
| return value !== value; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var x = NaN; | |
| console.log(x == NaN); // false | |
| console.log(x === NaN); // false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.log(isNaN(NaN)); // true | |
| console.log(isNaN(null)); // false | |
| console.log(isNaN(undefined)); // true | |
| console.log(isNaN(Infinity)); // false | |
| console.log(Number.isNaN(NaN)); // true | |
| console.log(Number.isNaN(null)); // false | |
| console.log(Number.isNaN(undefined)); // false | |
| console.log(Number.isNaN(Infinity)); // false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.log(undefined == null); // true | |
| console.log(undefined === null); // false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isNull(value) { | |
| return value === null; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.log(typeof ""); // "string" | |
| console.log(typeof "hello"); // "string" | |
| console.log(typeof String("hello")); // "string" | |
| console.log(typeof new String("hello")); // "object" | |
| console.log(typeof 0); // "number" | |
| console.log(typeof -0); // "number" | |
| console.log(typeof 0xff); // "number" | |
| console.log(typeof -3.142); // "number" | |
| console.log(typeof Infinity); // "number" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Использование typeof для идентификатора, | |
| // объявленного с блочной областью видимости, | |
| // создаст ошибку `ReferenceError` | |
| console.log(typeof tdzVariable === 'undefined'); // ReferenceError | |
| const tdzVariable = 'I am initialized.'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.log(undeclaredVariable === undefined); // ReferenceError | |
| console.log(typeof undeclaredVariable === 'undefined'); // true |