truthy and falsy values in javascript
// Falsy values:
0
''
undefined
null
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 trueif (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)
// Truthy values:
// All values are truthy, BUT (excluding) the following:
0
''
undefined
null
NaN
Also in JavaScript:
- form validation for email in js
- dm message collector discordjs
- how to print an array in javascript
- string to int javascript
- javascript null check
- jquery submit form
- Unable to resolve "react-navigation-stack" react native
- js remove last character
- json parse
- javascript math.pow
- looping through an object of objects with arrays
- get client timezone offset in JavaScript
- flutter betterplayer get aspect ratio
- js after settimeout
- javascript group by key
- javascript clone array of objects
- how can use css grandchild selector on js
- see all functions in a website with console
- javascript get values from object
- javascript set attribute href
- lowercase javascript
- hoisting js
- fillstyle
- javascript string ends with