what is truthy and falsy in javascript code example
Example 1: Truthy and Falsy js
function truthyOrFalsy (val) {
if(val) {
return true
} else {
return false
}
}
console.log(truthyOrFalsy(0))
console.log(truthyOrFalsy(5))
Example 2: truthy and falsy values in javascript
if (true)
if ({})
if ([])
if (42)
if ("0")
if ("false")
if (new Date())
if (-42)
if (12n)
if (3.14)
if (-3.14)
if (Infinity)
if (-Infinity)
Example 3: JS truthy value of void
function coolFunction() {
}
let truthyValue = (coolFunction() == true)