Arrays

Let’s say, hypothetically, that you have an ordered list of values. (A rarity in software, I know, but bear with me.) You could use any old object to store those values, but arrays (which inherit the properties of the Array prototype) offer you several nice conveniences.[31] They also, as a practical matter, improve performance by hinting that the JavaScript runtime should allocate a sequential block of memory.

Arrays can be defined using JSON-style syntax:

 mcFlys = [​'George'​, ​'Lorraine'​, ​'Marty'​]

All arrays in JavaScript are dynamic, with (practically) unlimited length. So you could define the exact same array one piece at a time:

 mcFlys = []
 mcFlys[0] = ​'George'
 mcFlys[1] = ​'Lorraine'
 mcFlys[2] = ​'Marty'

The use of ...

Get CoffeeScript, 2nd Edition 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.