CoffeeScript basics
Let's get started! We'll begin with something simple:
x = 1 + 1
You can probably guess what JavaScript this will compile to:
var x; x = 1 + 1;
Statements
One of the very first things you will notice about CoffeeScript is that there are no semicolons. Statements are ended by a new line. The parser usually knows if a statement should be continued on the next line. You can explicitly tell it to continue to the next line by using a backslash at the end of the first line:
x = 1\ + 1
It's also possible to stretch function calls across multiple lines, as is common in "fluent" JavaScript interfaces:
"foo" .concat("barbaz") .replace("foobar", "fubar")
You may occasionally wish to place more than one statement on a single line (for purely stylistic purposes). This is the one time when you will use a semicolon in CoffeeScript:
x = 1; y = 2
Both of these situations are fairly rare. The vast majority of the time, you'll find that one statement per line works great. You might feel a pang...