Course contentsShow
← JavaScript
Lesson 578 of 2,72314. The 'this' KeywordFree lesson

When to Choose Arrow vs Regular Functions

Decision rules: use arrows for callbacks and lexical 'this'; use regular functions for methods and constructors.

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:

  1. Writing callbacks – Array methods (.map(), .filter()), event handlers where you want to preserve the outer this, timers, and promises all benefit from lexical this binding:

    myButton.addEventListener('click', () => {
      this.handleClick(); // 'this' is the surrounding context
    });
    
  2. You want lexical 'this' – Any time you need this to refer to the enclosing scope rather than the call-site, arrows are your tool.

Use regular functions when:

  1. Defining object methods – When you want this to refer to the object itself at call-time:

    const user = {
      name: 'Alice',
      greet: function() { // NOT an arrow
        console.log(`Hi, I'm ${this.name}`);
      }
    };
    
  2. Writing constructors – Arrow functions cannot be used with new because they don't create their own this binding.

  3. You need the arguments object – 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.