Skip to content

Instantly share code, notes, and snippets.

@ranamahmud
Created November 7, 2020 11:03
Show Gist options
  • Save ranamahmud/3e8d1e18676b0bee1f5f999b77e097d6 to your computer and use it in GitHub Desktop.
Save ranamahmud/3e8d1e18676b0bee1f5f999b77e097d6 to your computer and use it in GitHub Desktop.
// truthy values
// true, {}, [], any number, "0"
// "false" inside quote or any quoted string
// new Date()
// Infinity, -Infinity
// biginteger number
if (true) {
console.log('condition is true');
} else {
console.log('condition is false');
}
// condition is true
if ({}) {
console.log('condition is true');
} else {
console.log('condition is false');
}
// condition is true
if ([]) {
console.log('condition is true');
} else {
console.log('condition is false');
}
// condition is true
if ("0") {
console.log('condition is true');
} else {
console.log('condition is false');
}
// condition is true
if ("false") {
console.log('condition is true');
} else {
console.log('condition is false');
}
// condition is true
if (Infinity) {
console.log('condition is true');
} else {
console.log('condition is false');
}
// condition is true
if (-Infinity) {
console.log('condition is true');
} else {
console.log('condition is false');
}
// condition is true
// 0, -0, 0n (big integer 0)
// ""
// false
// undefined
// null
// NaN
if (0) {
console.log('condition is true');
} else {
console.log('condition is false');
}
//condition is false
if (-0) {
console.log('condition is true');
} else {
console.log('condition is false');
}
//condition is false
if (0n) {
console.log('condition is true');
} else {
console.log('condition is false');
}
//condition is false
if (false) {
console.log('condition is true');
} else {
console.log('condition is false');
}
//condition is false
if (undefined) {
console.log('condition is true');
} else {
console.log('condition is false');
}
//condition is false
if (NaN) {
console.log('condition is true');
} else {
console.log('condition is false');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment