EN
JavaScript - Truthy and Falsy values
3
points
In this article, we would like to show you Truthy and Falsy values in JavaScript.
Falsy values / expressions |
---|
undefined |
null (object) |
false (boolean) |
empty string e.g |
zero number e.g 0 , +0 , -0 , 0n |
NaN (number) |
Note:
Any other value / expression is truthy (returns
true
).
Practical example
In the below example, we check if a value is truthy or falsy using a simple if statement.
Runnable example:
// ONLINE-RUNNER:browser;
const x = {};
if (x) {
console.log('Truthy');
} else {
console.log('Falsy');
}
Note:
Change the
x
value and run the example to check if the value is truthy or falsy.