Skip to content

Instantly share code, notes, and snippets.

@alexnm
Created January 10, 2016 17:23
Show Gist options
  • Save alexnm/430cb502ede98925bbaa to your computer and use it in GitHub Desktop.
Save alexnm/430cb502ede98925bbaa to your computer and use it in GitHub Desktop.
// Default parameters
const add = ( a, b = 1 ) => a + b;
add( 2, 4 ); // 6 - add
add( 3 ); // 4 - increment
// Rest parameters
const add = ( ...args ) => args.reduce( ( a, b ) => a + b );
add( 2, 4 ); // 6
add( 1, 2, 3, 4, 5 ); // 15
add( 5 ); // 5
// first = 1, second = 2, rest = [ 3, 4, 5 ]
const [ first, second, ...rest ] = [ 1, 2, 3, 4, 5 ];
// Spread parameters
const add = ( a, b, c ) => a + b + c;
add( ...[ 1, 2, 3 ] ); // 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment