As the title said, I can't quite understand why (true && {}) gives me {}, but the reverse is not the same.
Edit: As a followup, since I'm using a boolean operator, why does this expression not give me a boolean when evaluated?
The expression operands to && are evaluated left to right. The value of the && expression is the value of the subexpression last evaluated. In your case, that'll be the right-most expression in both cases.
So, with (true && {}), the && operator first evaluates true. It's not falsy, so it then evaluates {} and returns that expression result.
With ({} && true) it does the same things backwards, so the second expression evaluated is true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With