-
Book Overview & Buying
-
Table Of Contents
CoffeeScript Application Development
By :
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;
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...
Change the font size
Change margin width
Change background colour