Difference between Arrow and Regular functions in javascript | Javascript interview Question

preview_player
Показать описание
Understanding the differences between regular and arrow functions helps choose the right syntax for specific needs.

this value inside a regular function is dynamic and depends on the invocation. But this inside the arrow function is bound lexically and equals to this of the outer function.

arguments object inside the regular functions contains the arguments in an array-like object.

If the arrow function has one expression, then the expression is returned implicitly, even without using the return keyword.

Last but not least, you can define methods using the arrow function syntax inside classes. Fat arrow methods bind this value to the class instance.

Anyhow the fat arrow method is invoked, this always equals the class instance, which is useful when the methods are used as callbacks.

#javascript #javascriptinterview #arrowfunction #js #frontend
Рекомендации по теме
join shbcf.ru