Created
January 10, 2016 17:23
-
-
Save alexnm/430cb502ede98925bbaa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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