Logical operators are Operators logically resolve the expression. When I refer to "true" in the following table, I mean anything that isn't nil or false. In the not category when I say "opposite of boolean" I mean opposite of nil or false (which is true), and anything else is returned false.
|If a and b are both true. Returns last operand.||If a or b is true. Returns true one.||Returns the opposite of the boolean.|
The following is an example of the and operator.
2 3 nil false nil
The following is an example of the or operator.
1 2 true true nil
The following is an example of the not operator.
false false true true false
These operators are commonly used within a conditional. By taking them out of the conditional, you can create much better code. For example, you can use the or operator to create default values. This is great for creating optional arguments in a function constructor.
The following is an example of having a default value using or.
Hello world No argument specified