Skip to content

Instantly share code, notes, and snippets.

@aGuyNamedJonas
Created May 30, 2016 14:50
Show Gist options
  • Save aGuyNamedJonas/3ca1ca5b6558b9c9baeddc139927a5c7 to your computer and use it in GitHub Desktop.
Save aGuyNamedJonas/3ca1ca5b6558b9c9baeddc139927a5c7 to your computer and use it in GitHub Desktop.
Arrow function syntax, taken from the MDN page (#GistToSelf)

###Basic Syntax

(param1, param2, , paramN) => { statements }
(param1, param2, , paramN) => expression
         // equivalent to:  => { return expression; }

// Parentheses are optional when there's only one parameter:
(singleParam) => { statements }
singleParam => { statements }

// A function with no parameters requires parentheses:
() => { statements }

###Advanced Syntax

// Parenthesize the body to return an object literal expression:
params => ({foo: bar})

// Rest parameters and default parameters are supported
(param1, param2, ...rest) => { statements }
(param1 = defaultValue1, param2, , paramN = defaultValueN) => { statements }

// Destructuring within the parameter list is also supported
var f = ([a, b] = [1, 2], {x: c} = {x: a + b}) => a + b + c;
f();  // 6

Source: MDN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment