Why do arrow functions not have the arguments array?

JavascriptLambdaEcmascript 6ArgumentsAnonymous Function

Javascript Problem Overview


function foo(x) {
   console.log(arguments)
} //foo(1) prints [1]

but

var bar = x => console.log(arguments) 

gives the following error when invoked in the same way:

Uncaught ReferenceError: arguments is not defined

Javascript Solutions


Solution 1 - Javascript

Arrow functions don't have this since the arguments array-like object was a workaround to begin with, which ES6 has solved with a rest parameter:

var bar = (...arguments) => console.log(arguments);

arguments is by no means reserved here but just chosen. You can call it whatever you'd like and it can be combined with normal parameters:

var test = (one, two, ...rest) => [one, two, rest];

You can even go the other way, illustrated by this fancy apply:

var fapply = (fun, args) => fun(...args);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionConquerorView Question on Stackoverflow
Solution 1 - JavascriptSylwesterView Answer on Stackoverflow