In JS arguments array in functions is a special object that can be used to get all the arguments passed to the function. Similar to this, arrow functions do not have their own binding to a arguments object, they are bound to arguments of enclosing scope.
Arrow functions are callable but not constructable
If a function is constructable, it can be called with new, i.e. new User(). If a function is callable, it can be called without new (i.e. normal function call).
Functions created through function declarations / expressions are both constructable and callable.
Arrow functions (and methods) are only callable. class constructors are only constructable.
If you are trying to call a non-callable function or to construct a non-constructable function, you will get a runtime error
let arrowFunc = () => {}
new arrowFunc()
This code gives the error:
arrowFunc is not a constructor
I don’t want to sell you my point of view, instead I suggest you read what they say here and get your own idea based on your style of writing code. developer.mozilla.org/en-US/docs/W...
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Why need arrow function?
Is it comes with just short our code or ........what?
Not really. Arrow functions don't have their own
this
, which can be handy in some cases.Arrow functions do not have a arguments array
In JS arguments array in functions is a special object that can be used to get all the arguments passed to the function. Similar to this, arrow functions do not have their own binding to a arguments object, they are bound to arguments of enclosing scope.
Arrow functions are callable but not constructable
If a function is constructable, it can be called with new, i.e. new User(). If a function is callable, it can be called without new (i.e. normal function call).
Functions created through function declarations / expressions are both constructable and callable.
Arrow functions (and methods) are only callable. class constructors are only constructable.
If you are trying to call a non-callable function or to construct a non-constructable function, you will get a runtime error
source
I don’t want to sell you my point of view, instead I suggest you read what they say here and get your own idea based on your style of writing code.
developer.mozilla.org/en-US/docs/W...