Created
February 6, 2020 18:28
-
-
Save r3dm1ke/8b6f9453202ea60ca648fb09b492c8ec to your computer and use it in GitHub Desktop.
Showing type coercion in JavaScript
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
| /* Here, '5' will be converted to 5 */ | |
| 5 == '5'; // true | |
| 5 === '5'; // false | |
| /* Here, true will be converted to 1 */ | |
| 1 == true; // true | |
| 1 > false; // true | |
| 0 === false; // false | |
| // Here, JS will try to convert both of these to number | |
| // Number('true') = NaN (Not a Number), but Number(true) = 1 | |
| 'true' == true; // false | |
| 'true' === true; // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment