arrow functions howto Traditional Function var f function a return a 100 console log f 2 Arrow Function Break Down 1 Remove the word function and place arrow between the argument and opening body bracket f a return a 100 console log f 2 2 Remove the body brackets and word return the return is implied f a a 100 console log f 1 3 Remove the argument parentheses f a a 100 console log f 1 arrow functions Traditional Function function test a b return a b 100 console log test 1 2 Arrow Function test a b a b 100 console log test 1 2 Traditional Function no arguments let a 4 let b 2 function foo return a b 100 console log foo Arrow Function no arguments foo a b 100 console log foo console log done rest parameters howto function sum theArgs console log theArgs return theArgs reduce previous current return previous current console log sum 1 2 3 expected output 6 console log sum 1 2 3 4 expected output 10 Isn t rest just the same as argument object No List the main difference between rest parameters and the arguments object The arguments object is not a real array while rest parameters are Array instances meaning methods like sort map forEach or pop can be applied on it directly The arguments object has additional functionality specific to itself like the callee property The restParam bundles all the extra parameters into a single array therefore it does not contain any named argument defined before the restParam Whereas the arguments object contains all of the parameters including all of the stuff in the restParam unbundled existing arguments builtin approach function foo console log arguments foo 4 5 6
e log theArgs return theArgs reduce previous current return previous current console log sum 1 2 3 expected output 6 console log sum 1 2 3 4 expected output 10 Isn t rest just the same as argument object No List the main difference between rest parameters and the arguments object The arguments object is not a real array while rest parameters are Array instances meaning methods like sort map forEach or pop can be applied on it directly The arguments object has additional functionality specific to itself like the callee property The restParam bundles all the extra parameters into a single array therefore it does not contain any named argument defined before the restParam Whereas the arguments object contains all of the parameters including all of the stuff in the restParam unbundled existing arguments builtin approach function foo console log arguments foo 4 5 6