Why an OR expression can stop early

In many programming languages, `A || B` means “A or B”: the whole expression is true if either condition is true. The program checks the conditions from left to right. If `A` is already true, the answer is settled, so there is no need to evaluate `B`.

This behavior is called short-circuit evaluation. It can avoid unnecessary work—for example, skipping a costly lookup when an earlier check already decides the result. It can also make a second condition safe to evaluate only in certain circumstances. A program might first check that an object exists, then inspect one of its properties; if the first check fails, the property access is skipped.

Skipped work can also mean skipped effects

Evaluation is not always just checking a value. A function call might write to a file, update a counter, send a request, or display a message. If that call appears in the second part of an OR expression, it runs only when the first condition is false. When the first condition is true, the function is never called.

That can cause bugs when a programmer assumes both sides will run—for example, placing necessary setup or an update in the second condition. The expression may still produce the intended true-or-false answer while silently omitting that action.

Short-circuiting is therefore both an efficiency feature and a control-flow decision. When reading an OR expression, ask not only what each condition returns, but also whether evaluating either one changes anything.