JavaScript: Logic and Comparison Operators
We all should remember the less than (< ) and greater than (>) from math classes back in school. Logical operators extended more into philosophy classes. The use of these symbols is widely used for comparisons and logical operations in numerous programming languages. The usage is not too much different that what it was back in our classes. The comparison symbols are used to indicate whether a value is less than, greater than, or equal to another value, while logical operators compare conditions to check if a resulting condition is true or false.
The comparison operators:
“==” – A pair of sequential equal signs become the “Is Equal To” comparison
“===”-Three equal signs in a row becomes the “Is Exactly Equal To” comparison
“!=” – An exclamation point followed by an equal sign represents “Not Equal To”
“>” – An opening to the left still stands for “Greater Than”
“<” – An opening to the right still means “Less Than”
“>=”—Greater than or equal to
“<=”—Less than or equal to.
The logical operators:
“&&”- Two consecutive Ampersands represent a logical “AND”. Will compare two or more conditions and will return “true”, if all of the conditions are true. Otherwise the result is false.
“||”—Two consecutive pipes represents a logical “Or”. The result will be true if one or both of the compared conditions is true. It will only return “false” if both conditions are false
“!”—The Exclamation point is used to symbolize “Not”. Placing this in front of an expression will return the opposite of the resulting value.
Examples:
Let A=True, B=True, C=False
A && B = True A || B= True A && C = False A || C=True !A=False
5b42dfc8-25fb-4f07-9714-5066567de189|0|.0