You’ll often want to compare the value of one variable with another, or the value of a variable against a literal value (i.e., a value typed into the expression). For example, you might want to compare the value of the day of the week to “Tuesday”, and you can do this by checking if todaysDate == "Tuesday" (note that double equal sign). A complete list of comparisons is in Table 1.5.
Comparison | What it does |
---|---|
x == y | Returns true if x and y are equal |
x != y | Returns true if x and y are not equal |
x > y | Returns true if x is greater than y |
x > = y | Returns true if x is greater than or equal to y |
x < y | Returns true if x is less than y |
x <= y | Returns true if x is less than or equal to y |
x && y | Returns true if both x and y are true |
x || y | Returns true if either x or y is true |
!x | Returns true if x is false |
✓ Tip
If you are comparing strings, be aware that “a” is greater than “A” and that “abracadabra” is less than “be”.
18.222.104.196