HuntExams Academy logo
JavaScriptIntermediate#functions#es6

Difference between arrow functions and regular functions?

Answer

Arrow functions have no own this, arguments, new.target or prototype, cannot be used with new, and cannot be generators. They are ideal for callbacks and bad for object methods or constructors.

Example

const obj = { v: 1, get(){ return [1].map(() => this.v); } };
obj.get(); // [1] — arrow keeps outer this
new (() => {})(); // TypeError

Related Interview Questions

1
JavaScriptIntermediate#prototypes#oop

What is prototypal inheritance?

Open
2
JavaScriptIntermediate#oop#es6

What is the difference between an ES6 class and a constructor function?

Open
3
JavaScriptAdvanced#event-loop#async

Explain the event loop.

Open