Relational expression (Definition)

Relational expressions yield a Boolean result.

Availability:

ECMAScript edition - 2
Property/method value type:Boolean primitive

Relational expressions yield a Boolean result according to the relational test of the values either side of the operator.

Numerical values are compared according to sign and magnitude while string values are compared according to the Unicode collating sort sequence.

Relational operators will attempt to convert both arguments to a Number, and if at least one argument can be converted to a Number then the other will be forced to be a Number for comparison purposes. If both arguments are Strings or string-like objects, the relational test will be String-based.

If a prefixing plus sign is present, then a numeric coercion of a string takes place before the comparison.

Example code:

   // Force a string comparison
   myResult = (a+'' <= b+'');
   // Force a numeric comparison
   myResult = (a-0 <= b-0);
   // Force a boolean comparison
   myResult = (!a <= !b);

See also:Equal to (==), Equality expression, Expression, Greater than (>), Greater than or equal to (>=), Identically equal to (===), Less than (<), Less than or equal to (<=), NOT Equal to (!=), NOT Identically equal to (!==), Relational operator, Type conversion

Cross-references:

ECMA 262 edition 2 - section - 11.8

ECMA 262 edition 3 - section - 11.8

Wrox Instant JavaScript - page - 37

Wrox Instant JavaScript - page - 39