Jasyn Marais

Truthiness

13 February 2023

In JavaScript, a truthy value is a value that is considered true when encountered in a Boolean context, while a falsy value is a value that is considered false when encountered in a Boolean context.

A "truthy" value is any value that, when evaluated in a Boolean context, is considered true. Examples of truthy values include:

A "falsy" value is any value that, when evaluated in a Boolean context, is considered false. Examples of falsy values include:

The concept of truthiness is important when writing conditional statements in JavaScript. For example, you might use an if statement to check whether a value is truthy or falsy:

let myValue = 5;

if (myValue) {
    console.log("myValue is truthy");
} else {
    console.log("myValue is falsy");
}

In this example, the if statement will output "myValue is truthy", because myValue is a truthy value (specifically, the number 5).