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

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.