Comparisons

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.

Table 1.5. Comparisons
ComparisonWhat it does
x == yReturns true if x and y are equal
x != yReturns true if x and y are not equal
x > yReturns true if x is greater than y
x > = yReturns true if x is greater than or equal to y
x < yReturns true if x is less than y
x <= yReturns true if x is less than or equal to y
x && yReturns true if both x and y are true
x || yReturns true if either x or y is true
!xReturns 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”.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.104.196