JavaScript Quiz #06: Truthy and Falsy Values — Interview Questions

quizzesforyou.com
4 min readJun 30, 2023

What are Truthy and Falsy Values In JavaScript? How to use Truthy and Falsy Values in JavaScript?

Checkout the interactive quiz https://quizzesforyou.com/quiz/jstruthyfalsy

Checkout All JavaScript quizzes

In JavaScript, values can be classified as either truthy or falsy. Knowing which values are considered truthy or falsy allows you to write more concise and effective code. Let’s explore truthy and falsy values in JavaScript with code examples.

Truthy Values:

Truthy value is any value that is considered true when evaluated in a Boolean context. The following values are considered truthy:

  1. Non-empty strings: Any string that contains at least one character is considered truthy.
var name = "John";
if (name) {
console.log("Hello, " + name);
}

Output: "Hello, John"

2. Numbers: Any nonzero number (positive or negative) is considered truthy.

var count = 42;
if (count) {
console.log("Count is: " + count);
}

Output: "Count is: 42"

3. Objects: Any JavaScript object, including arrays and functions, is considered truthy.

var person = {
name: "Alice",
age: 25
};
if…

--

--