Catalog / CoffeeScript Cheatsheet
CoffeeScript Cheatsheet
A concise reference for CoffeeScript, covering syntax, features, and best practices for this elegant JavaScript dialect.
Core Syntax
Basic Structure
Function Definition |
Equivalent to:
|
Implicit Return |
CoffeeScript functions implicitly return the value of the last expression.
|
Object Literals |
Equivalent to:
|
Array Literals |
Equivalent to:
|
String Interpolation |
Results in:
|
Multiline Strings |
Equivalent to:
|
Operators and Keywords
|
Equality checks.
|
|
Logical NOT.
|
|
Logical AND and OR.
|
|
The opposite of
|
|
Shorthand for
|
|
Existential operator. Returns
|
Control Flow & Loops
Conditional Statements
|
|
|
|
|
|
Loops
|
Iterates over the keys of an object.
|
|
Iterates over the elements of an array.
|
|
Creates a range-based loop.
|
|
|
|
The opposite of
|
List Comprehensions
CoffeeScript’s list comprehensions provide a concise way to generate arrays.
With conditions:
|
Classes & Objects
Class Definition
Basic Class |
|
Inheritance |
|
Class Variables |
|
Object Creation
Creating instances of classes is straightforward:
|
Prototypes
CoffeeScript classes automatically manage prototypes, making inheritance and method sharing simple.
|
Functions
Function Definition
Basic Function |
|
Functions with no arguments |
|
Multiline Functions |
|
Arguments
Default Arguments |
|
Splats (Variable Arguments) |
|
Bound Functions
Use
|