// this alls are truthy values including empty object and array,
// excluding empty string (empty string is falsy value)
if ([]) {
console.log('✅ This runs');
}
if ({}) {
console.log('✅ This runs');
}
if (true) {
console.log('✅ This runs');
}
if ('test') {
console.log('✅ This runs');
}
// Truthy values
/*
true
{}
[]
42
"0"
"false"
new Date()
-42
12n
3.14
-3.14
Infinity
-Infinity
*/
// Falsy values
/*
false
0
-0
0n
"", '', ``
null
undefined
NaN
*/
//Checking truthy and falsy value
function truthyOrFalsy (val) {
if(val) {
return true
} else {
return false
}
}
console.log(truthyOrFalsy(0)) // print false
console.log(truthyOrFalsy(5)) // print true