Decision-making Logic

JS has three main operators: || (OR), && (AND), and ! (NOT). But they can do much more than just work with true/false.

1. OR (||)

Finds the first truthy value.

alert( null || 0 || "Ok" || false ); // "Ok"

This is often used to set default values: let name = user.name || "Anonymous".

2. AND (&&)

Finds the first falsy value.

alert( 1 && 2 && null && 3 ); // null

Useful for executing code only if a condition is true: isAdmin && alert("Hello!").

3. NOT (!)

Converts to a boolean type and inverts it.

alert( !!"text" ); // true (double negation is the fastest way to cast to Boolean)
Tip

Precedence: First !, then &&, and only then ||. You can always use parentheses to avoid confusion.