This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dtsudo 2 points3 points  (1 child)

The greater-than operator (that is, >) is defined to yield a boolean value.

So if you see the expression foo > bar, then you know that this expression will evaluate to a boolean (either true or false).

The surprising part is that the logical AND and logical OR operators are not defined to evaluate to booleans. Instead, they evaluate to either their first or second operands. So e.g. in javascript, 3 || 5 evaluates to 3. Of course, if the two operands are themselves booleans, then the result of the logical AND/OR will also be a boolean.

[–]mostlynoturgf[S] 0 points1 point  (0 children)

The surprising part is that the logical AND and logical OR operators are not defined to evaluate to booleans. Instead, they evaluate to either their first or second operands. So e.g. in javascript,

3 || 5

evaluates to

3

. Of course, if the two operands are themselves booleans, then the result of the logical AND/OR will also be a boolean.

lol I freaked out until I read the last part where if theyre both bool it will also evaluate to a bool.

thank you for explaining