Comparison operators are often used in the if statements (Section 15.6): two operands are compared and the flow of the program proceeds according to the result of the comparison.
The Equal operator returns true if its operands' values are equal; otherwise returns false:
true
false
After defining the following variables:
var1 = 5; var2 = "foo";
true
false
Important: Numbers and strings are always considered different:
false
The same holds for a null and an undefined value; suppose that no variable called
never_defined
has ever been defined in your script:
0 (false)
0 (false)
Two undefined variables are equal:
1 (true)
The Not Equal operator returns true if its operands' values are different; otherwise returns false:
false
true
After defining the following variables:
var1 = 5; var2 = "foo";
false
true
Important: Numbers and strings are always considered different:
true
The same holds for a null and an undefined value; suppose that non variable
called never_defined
has ever been defined in your
script:
1 (true)
1 (true)
Two undefined variables are equal:
0 (false)
The Weak Equal operator behaves like Equal with two exceptions:
When applied to operands of different type (a number and a string), it tries to convert the string in an integer, and then performs the comparison.
Undefined and null values are considered equal.
true
1 (true)
1 (true)
The Weak Not Equal operator behaves like Not Equal with two exceptions:
When applied to operands of different type (a number and a string), it tries to convert the string in an integer, and then performs the comparison.
Undefined and null values are considered equal.
0 (false)
0 (false)
0 (false)
Applied to integers, this operator returns true if the first operand is greater than the second. Otherwise, it returns false. Applied to strings, returns true if the first operand follows the second in alphabetical order. Otherwise, it returns false.
0 (false)
1 (true)
1 (true)
Applied to integers, this operator returns true if the first operand is greater than or equal to the second. Otherwise, it returns false. Applied to strings, returns true if the first operand follows the second in alphabetical order or if they are equal. Otherwise, it returns false.
1 (true)
1 (true)
Applied to integers, this operator returns true if the first operand is lower than the second. Otherwise, it returns false. Applied to strings, returns true if the first operand precedes the second in alphabetical order. Otherwise, it returns false.
0 (false)
0 (false)
0 (false)
Applied to integers, this operator returns true if the first operand is lower than or equal to the second. Otherwise, it returns false. Applied to strings, returns true if the first operand precedes the second in alphabetical order or if they are equal. Otherwise, it returns false.
1 (true)
1 (true)
This manual can be downloaded from http://www.g-cows.org/.