truthy | falsy |
---|---|
1 | 0 |
true | false |
non 0 value | undefined |
" " or "anything" | null, "" |
any numbers | NaN |
{}, [] | - |
Last active
August 22, 2020 11:45
-
-
Save iamsaief/61505ae4630a6156c7524d96b0af9d56 to your computer and use it in GitHub Desktop.
This file contains 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
/* Truthy/Falsy value */ | |
let age = 0; | |
if (age) { | |
console.log(true); | |
} else { | |
console.log(false); | |
} | |
// Output : false | |
let name; // undefined, falsy | |
// name = "Smith"; // truthy | |
// name = " "; //truthy | |
// name = []; //truthy | |
// name = {}; //truthy | |
console.log(name); | |
if (name) { | |
console.log(true); | |
} else { | |
console.log(false); | |
} | |
// Output : false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment