Control Flow & Loops
What is short-circuit evaluation in JavaScript?
Short-circuit evaluation in JavaScript is a technique to optimize code execution by skipping unnecessary operations in logical expressions. For the logical AND (&&) operator, if the first operand evaluates to false, the second operand is not evaluated because the result will be false regardless. For the logical OR (||) operator, if the first operand evaluates to true, the second operand is not evaluated because the result will be true regardless. This behavior is leveraged in patterns like: user && user.name (only accesses name if user exists) or result = value || defaultValue (uses defaultValue only if value is falsy).