Chapter 14.3.1. The Comparison Problem

JavaScript provides a typical set of comparison operators: ==, !=, <, >, <=, =>. Starting by looking at just equality, JavaScript has two different ways to test equality: the standard == and the less-standard ===. == will try to change the type of the objects being compared in an effort to see whether they match. For example, “1” == 1 is true in JavaScript. The === is stricter: It doesn’t do any kind of type conversion. So, “1” === 1 is false.

JavaScript will also do type conversions for expressions such as “1” < 2. You might be thinking that JavaScript’s comparison operators seem straightforward to use. And you’d be correct if you’re only comparing some combination of numbers or strings. ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites 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.