Arrays

Arrays, at their most simple, look very similar to JavaScript.

languages = [ "english", "spanish", "french" ]
console.log languages[1]

You may use a trailing comma and it will be compiled away:

languages = [
  "english",
  "spanish",
  "french",
]

becomes:

var languages;
languages = ["english", "spanish", "french"];

Many people prefer this style, as it makes it easier to change the contents of an array or object. And you'll be thankful for this safeguard if you've ever left a trailing comma in a JavaScript array, only to discover (always at a very inconvenient time) that it causes an execution-halting error in one particular browser. The browser in question will remain unnamed for the sake of our collective blood pressure. I want this book to be a ...

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.