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/.
Other than that surprise, the other common JavaScript operators are all present and work as you might expect.
if 1 < 2 && 3 >= 2 if false || true if !false console.log "All is well."
However...