Arrow function vs function declaration / expressions: Are they equivalent / exchangeable?
Arrow function vs function declaration / expressions: Are they equivalent / exchangeable? Canonical question If you find a question about issues after replacing a function declaration / expression with an arrow function, please close it as duplicate of this one. Arrow functions in ES2015 provide a more concise syntax. Can I replace all my function declarations / expressions with arrow functions now? What do I have to look out for? Examples: Constructor function function User(name) { this.name = name; } // vs const User = name => { this.name = name; }; Prototype methods User.prototype.getName = function() { return this.name; }; // vs User.prototype.getName = () => this.name; Object (literal) methods const obj = { getName: function() { // ... } }; // vs const obj = { getName: () => { // ... } }; Callbacks setTimeout(function() { // ... }, 500); // vs setTimeout(() => { // ... }, 500); Variadic functions function sum() { let args = .slice(arguments...