Comparison operators

Now that we know how to use these control structures, let's learn about some comparison operators we can use to test the truthfulness of useful questions. There's one big surprise in here, so let's get that out of the way. == and != in CoffeeScript don't compile to their equivalents in JavaScript.

1 == 2
3 != 4

becomes:

1 === 2;
3 !== 4;

Note

According to the CoffeeScript documentation, this decision was made because "the == operator frequently causes undesirable coercion, is intransitive, and has a different meaning than in other languages".

Most JavaScripters recommend using === and !== exclusively, so this is simply enshrining that best practice. If you wish to know more about this recommendation, read http://www.impressivewebs.com/why-use-triple-equals-javascipt/ ...

Get CoffeeScript Application Development 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.