When to Choose Arrow vs Regular Functions
You'll learn: The decision rules for when to reach for an arrow function versus a regular function based on what you're building.
Now that you understand how arrow and regular functions behave differently with this, you need practical guidelines for choosing between them in real code.
The Decision Rules
Use arrow functions when:
-
Writing callbacks – Array methods (
.map(),.filter()), event handlers where you want to preserve the outerthis, timers, and promises all benefit from lexicalthisbinding:myButton.addEventListener('click', () => { this.handleClick(); // 'this' is the surrounding context }); -
You want lexical 'this' – Any time you need
thisto refer to the enclosing scope rather than the call-site, arrows are your tool.
Use regular functions when:
-
Defining object methods – When you want
thisto refer to the object itself at call-time:const user = { name: 'Alice', greet: function() { // NOT an arrow console.log(`Hi, I'm ${this.name}`); } }; -
Writing constructors – Arrow functions cannot be used with
newbecause they don't create their ownthisbinding. -
You need the
argumentsobject – Regular functions provide it; arrows don't.
Think of It This Way
Arrows are "transparent" to this – they let it pass through from the outer scope. Regular functions are "opaque" – they create their own this based on how they're called. Choose based on which behavior you need.
Key Takeaway: Use arrow functions for callbacks and when you need lexical this; use regular functions for methods, constructors, and when you need dynamic this or the arguments object.