A short-circuit condition occurs when the evaluation of a logical expression stops as soon as the result is determined. This is common with logical AND
(&&
) and OR
(||
) operators.
- In an
AND
condition, if the first operand is falsy, the second operand is not evaluated. - In an
OR
condition, if the first operand is truthy, the second operand is not evaluated.
Example:
let a = false;
let b = true;
console.log(a && b); // 'false', 'b' is not evaluated
**Tags**: [intermediate](./level/intermediate), [JavaScript](./theme/javascript), [Logical Operators](./theme/logical_operators)