Last Updated: February 25, 2016
·
739
· fr0gs

Syntax for arrays in Coffeescript

Imagine you have an array such as:

l = [1, 2, 3, 4]

This line:

k = x*2 for x in l

Will return : 12, and this line:

k = (x*2 for x in l)

will return [2, 4, 6, 8]

Without parenthesis in CoffeeScript it is equivalent to a forEach() in javascript.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside