"An expression is any valid unit of code that resolves to a value."
Logical AND and Logical OR are binary operators, i.e. they require two operands. Those operands can be expressions because an expression resolves to a value. A function invocation is considered an expression because it will resolve to a value after the call (even if it is just undefined).
Given lhs && rhs the rhs expression will never be evaluated if lhs evaluates to a falsy value. That falsy value is what the && operator evaluates to.
Similarly with lhs || rhs the rhs expression will never be evaluated if lhs evaluates to a truthy value. That truthy value is what the || operator evaluates to.
So somethingFalsy && fn(value) won't execute fn(value) while somethingTruthy && fn(value) will execute fn(value). In the former case somethingFalsy will be the resulting value (ignored if not used) while whatever fn(value) returns is the result for the latter.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Being an operator it's part of an expression:
"An expression is any valid unit of code that resolves to a value."
Logical AND and Logical OR are binary operators, i.e. they require two operands. Those operands can be expressions because an expression resolves to a value. A function invocation is considered an expression because it will resolve to a value after the call (even if it is just
undefined
).On top of this
&&
and||
use short circuit evaluation:lhs && rhs
therhs
expression will never be evaluated iflhs
evaluates to a falsy value. That falsy value is what the&&
operator evaluates to.lhs || rhs
therhs
expression will never be evaluated iflhs
evaluates to a truthy value. That truthy value is what the||
operator evaluates to.So
somethingFalsy && fn(value)
won't executefn(value)
whilesomethingTruthy && fn(value)
will executefn(value)
. In the former casesomethingFalsy
will be the resulting value (ignored if not used) while whateverfn(value)
returns is the result for the latter.