Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why in Fat arrow functions arguments object is undefined [duplicate]

If we print the output of arguments variable inside a normal function:

var func = function() { console.log(arguments); }
func();

The result is an object which contains information about the context (parameter values, scope , functionLocation...)

But if we reproduce the same function with fat arrow, we will never get argument declared:

var func = () => { console.log(arguments); }
func();

// arguments is not defined

Can anyone explain how can we get the context data from arrow functions?

like image 826
Cristian Batista Avatar asked Jan 19 '26 03:01

Cristian Batista


1 Answers

According to MDN

An arrow function expression has a shorter syntax than a function expression and does not have its own this, arguments, super, or new.target. These function expressions are best suited for non-method functions, and they cannot be used as constructors.

like image 91
Oleh Chemerskyi Avatar answered Jan 21 '26 18:01

Oleh Chemerskyi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!