The most common use of short-circuit evaluations using logical operators is not performance, but error elimination. See this:
if (a && a.length)
You cannot just use & here.
Note that using & instead of && not possible if you are not dealing with booleans. For example, & at 2 ( 01 in binary format) and 4 ( 10 in binary format) 0 .
Note also that, in addition to if tests, && (like || ) is also used because it returns one of the operands :
"a" & "b" => 0 "a" && "b" => "b"
More generally, using & instead of && often possible. Just like skipping a majority ; in your javascript code. But it will make you think more than you need (or it will sometimes cause strange errors).
Denys seguret
source share