Show Menu

CoffeeScript language Cheat Sheet by

CoffeeScript language syntax
language     development     programming     javascript     web     intermediate     coffeescript     js

Instal­lation

Install NodeJs (htttp­://­nod­ejs.org/)
Install npm (nodejs included)
npm install coffee­-script -g

Usage

~$ coffee src/fi­le.c­offee
Run Coffee­Script file
~$ coffee -c -o output/ src/
Compile files from src to output
~$ coffee -e "­con­sol­e.log 'Hello World'­"
Evaluate Coffee­Script code
$ coffee --join output­/all.js --compile src/*.c­offee
Concat­enate the source Coffee­Script before compiling
~$ coffee
Start Read-e­val­-print loop
~$ coffee --output output/ -cw src/
Watch directory src for changes

Variables

language = 'Coffe­eSc­ript'

? - Existe­ntial Operator

coffee = 'espresso' if morning?
cups = 0; cups ?= 1
sugar = count ? 1
coffee = one?.c­off­ee?­().p­le­ase­?.n­o?.s­ugar?
 

Functions

hello = -> consol­e.log "­Hel­lo"
define function
hello()
call function
sum = (a, b) -> a + b
define function with args
sum 1, 2
call function with args
sum_mu­ltiply = (a, b) -> [ a + b, a * b]
define function
[ sum, multiply ] = sum_mu­ltiply 1, 2
call function
myFunc = (param = 'default') -> consol­e.log param
define function with default param
otherFunc = (first, other...) -> conole.log other
define function
otherFunc myArray...
call function with array as arguments

Scope

Notice how all of the variable declar­ations have been pushed up to the top of the closest scope, the first time they appear. outer is not redeclared within the inner function, because it's already in scope; inner within the function, on the other hand, should not be able to change the value of the external variable of the same name, and therefore has a declar­ation of its own.
 

Arrays

array = [1, 2, 3, 4]
Array with numbers from 1 to 4
array = [1...4]
Array with numbers from 1 to 3
array = [1..3]
Array with numbers from 1 to 3
array1 = array[­1..3]
Create new array from three items from array
array[­1..3] = [3, 2, 1]
Change three items of array
ground­_co­ffe­e.r­eve­rse()
Reverse elements in array
Math.max [12, 32, 11, 67, 1, 3]...
Max element of array
[1 ,2, 3].concat [ 4, 5, 6]
concat­enating arrays

Operators and aliases

Coff­eeS­cript
Java­Scr­ipt
this, @
this
is
===
isnt
!==
not
!
and
&&
or
||
true, yes, on
true
false, no, off
false
of
in
in
find element in array (No JS equiva­lent)

Download the CoffeeScript language Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/apk_coffeescript-language.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

RSrini RSrini, 11:11 15 Jul 15

array = [1....3]
Array with numbers from 1 to 4

There is no found dots. only 2 dots and 3 dots available.

When i try this the generated array become empty. Please update.

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          JavaScript Cheat Sheet
          CoffeeScript Cheat Sheet

          More Cheat Sheets by apk