Go Logical Operators
What are Logical Operators?
Logical operators are operators that act on booleans (i.e. true and false)
Logical And (&&
)
The logical and returns true only if both booleans are true. The symbol for the logical and operator is two ampersands: &&
. For example, true && false
gives false and true && true
gives true.
Logical Or (||
)
The logical or returns true if one of the two booleans returns true. The symbol for the logical or operator is ||
. For example. true || false
gives true and true || true
give true, but false || false
gives false.
Logical Not (!
)
The logical not simply returns the opposite of the given boolean. We use it like this: ![boolean]
. !true
returns false and !false
returns true.