Skip to main content
1 of 3
Mike Nakis
  • 32.8k
  • 7
  • 82
  • 116

This is correct, the short-circuit OR operator (||) will always return the same value as the non-short-circuit OR operator (|). However, if the first operand is true, the short-circuit operator will not cause evaluation of the second operand, while the non-short-circuit operator will always cause evaluation of both operands. This can have an impact in performance, and sometimes in side-effects.

So, there is a use for both: if you care for performance, and the evaluation of the second operand does not produce any side effects, (or if you do not care about them,) then by all means use the short-circuit operator. But if for some reason you need the side-effects of the second operand, then you should use the non-short-circuit operator.

Mike Nakis
  • 32.8k
  • 7
  • 82
  • 116