Skip to content

Instantly share code, notes, and snippets.

@iamsaief
Last active August 22, 2020 11:45
Show Gist options
  • Save iamsaief/61505ae4630a6156c7524d96b0af9d56 to your computer and use it in GitHub Desktop.
Save iamsaief/61505ae4630a6156c7524d96b0af9d56 to your computer and use it in GitHub Desktop.
/* 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
truthy falsy
1 0
true false
non 0 value undefined
" " or "anything" null, ""
any numbers NaN
{}, [] -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment