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 tryToReturnAnObject() { | |
| return | |
| { | |
| hello: "world" | |
| } | |
| } | |
| console.log(tryToReturnAnObject()) |
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
| const tryToReturnAnObjectArrowFunction = () => { | |
| hello: "world" | |
| } | |
| console.log(tryToReturnAnObjectArrowFunction()) |
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
| const actuallyReturnAnObjectArrowFunction = () => ({ | |
| hello: "world" | |
| }) | |
| console.log(actuallyReturnAnObjectArrowFunction()) |
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 actuallyReturnAnObject() { | |
| return { | |
| hello: "world" | |
| } | |
| } | |
| console.log(actuallyReturnAnObject()) |
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
| let failedMath = Math.sqrt(-37); | |
| console.log(failedMath); // NaN | |
| console.log(3 + failedMath); // NaN | |
| let failedStringParse = parseInt("Operation Doomsday", 10); | |
| console.log(failedStringParse); // NaN | |
| console.log(3 * failedStringParse); // NaN |
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
| let divisionByZero = 37 / 0; | |
| console.log(divisionByZero); // Infinity | |
| let divisionByEmptyString = 37 / ""; | |
| console.log(divisionByEmptyString); // Infinity | |
| let divisionByFalsy = 37 / false; | |
| console.log(divisionByFalsy); // Infinity | |
| let zeroOverZero = 0 / 0; |
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
| let myNaN = NaN; // or let myNan = Number.NaN | |
| console.log(typeof myNaN); // "number" | |
| console.log(myNaN == NaN); // false | |
| console.log(myNaN === 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
| let variable = NaN; // or let variable = Number.NaN | |
| // Check for NaN by checking for self-equality | |
| console.log(variable != variable); // true | |
| console.log(variable !== variable); // true | |
| // NaN is the only value that is not equal to itself | |
| let isNaN = (maybeNaN) => maybeNaN!=maybeNaN; | |
| console.log(isNaN(variable)); // true |
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
| let maybeNaN = NaN; | |
| console.log(Number.isNaN(maybeNaN)); // true | |
| maybeNaN = 3; | |
| console.log(Number.isNaN(maybeNaN)); // 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
| isNaN('hello world'); // true | |
| Number.isNaN('hello world'); // false |