Languages
[Edit]
EN

JavaScript - Truthy and Falsy values

3 points
Created by:
Admin Dirask Community
1810

In this article, we would like to show you Truthy and Falsy values in JavaScript.

 

Falsy values / expressions
NaN
null
undefined
boolean false
empty string e.g '', "", ``
any zero number e.g 0, +0, -0, 0n

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;

let 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.

See also

  1. JavaScript - convert string to boolean 
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join