falsy and truthy values javascript code example
Example 1: javascript falsy
// Falsy values:
0
''
undefined
null
NaN
Example 2: Truthy and Falsy js
//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
Example 3: javascript truthy
// Truthy values:
// All values are truthy, BUT (excluding) the following:
0
''
undefined
null
NaN