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.
// Force a string comparison myResult = (a+'' <= b+''); // Force a numeric comparison myResult = (a-0 <= b-0); // Force a boolean comparison myResult = (!a <= !b);
ECMA 262 edition 2 - section - 11.8
ECMA 262 edition 3 - section - 11.8
Wrox Instant JavaScript - page - 37
Wrox Instant JavaScript - page - 39
Prev | Home | Next |
Regular expression | Up | Relational operator |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |