I’m having a hard time understanding the difference between the comparison and logical “not” operators in Javascript. And I am confused about the syntax as well. My questions are:
Since they are both boolean operators, are there any real differences between the two?
And is the syntax for both like this?
x! = 5
Any explanation appreciated – please post examples if you can.
Comparison: take two values and compare them. We could ask various questions, for example:
The result of each of this is a boolean value. So we could write:
boolean areTheyEqual = ( x == y );
So aretheyEqual would be “true” if x was equal to y. Now suppose you wanted a variable “areTheyDifferent”. We could get that in two ways, either using the “not” operator, which works on a boolean value:
or we could use the “notEqual” comparison
So the ! operator takes a boolean value and “inverts” it. You need to read the
as a single comparison operator, just like >= is a single operator.