Search⌘ K

if-statements, continued

Explore how JavaScript evaluates truthy and falsey values inside if-statements. Understand how to write concise conditional logic using single-line statements, bracket usage, and chaining else-blocks. This lesson helps you write clearer and more effective if-statements in your JavaScript code.

We'll cover the following...

“Truthy” and “Falsey”

If-statements don’t work only with booleans. We can use any variable type inside the if-statement parentheses.

If we don’t use true or false variables, JavaScript will forcibly coerce whatever we put inside the parentheses to true or false. It’ll then decide whether to run the code or not.

A value that coerces to true is referred to as “truthy”. One that coerces to false is “falsey”.

So ...