I'm reading "Structure and Interpretation of Computer Programs: JavaScript Edition" (2022) by Abelson, Sussman et al. On page 64, the book talks about the "logical composition operations" (logical AND, logical OR):
- expression1 && expression2
This operation expresses logical conjunction, meaning roughly the same as the English word and. This syntactic form is syntactic sugar for
expression1 ? expression2 : false
;
- expression1 || expression2
This operation expresses logical disjunction, meaning roughly the same as the English word or. This syntactic form is syntactic sugar for
expression1 ? true : expression2
.
I don't understand how expression1 ? expression2 : false
could be the same thing as expression1 && expression2
.
In the first case, we just evaluate whether expression1 is truthy. In the second case, we evaluate whether both expression1 and expression2 are truthy. So why are they the same thing? I hope you can enlighten me? :) Thanks a lot!