Arrow Functions vs Regular Functions in JavaScript

Compare JavaScript arrow and regular functions, focusing on how they handle this, object methods, event listeners, arguments, and constructors.

Arrow Functions vs Regular Functions in JavaScript

Arrow Functions vs. Regular Functions: What's the Biggest Difference?

Arrow functions are shorter, but syntax length isn't the main reason to choose between them. The key difference is how they handle this: a regular function gets its this value from how it is called, while an arrow function uses this from the surrounding scope where it was created.

We'll compare them in array callbacks, object methods, and event listeners, and see why arrows can't be constructors. Run the JavaScript examples in a modern browser console or recent Node.js. The event-listener example needs a browser page.

The syntax is different

A regular function declaration looks like this:

function add(a, b) {
  return a + b;
}

The same operation as an arrow function:

const add = (a, b) => a + b;

For a single parameter, parentheses can be omitted; for a one-expression body, the value is returned implicitly. But keep the braces and return when you need multiple statements:

const describe = (name) => {
  const message = `Hello, ${name}!`;
  return message;
};

The important difference: this

With a regular function, this depends on the call. When a regular function is called as an object method, this refers to the object before the dot:

const user = {
  name: "Mina",
  sayName() {
    console.log(this.name);
  },
};

user.sayName(); // Mina

An arrow function doesn't create its own this. It uses the value from the surrounding scope where the arrow was created. That makes arrows handy for callbacks that need to use the surrounding this, but it often makes them a poor fit for object methods:

const user = {
  name: "Mina",
  sayName: () => {
    console.log(this.name);
  },
};

user.sayName(); // Not "Mina"; this comes from outside the object

The exact outer value depends on the surrounding context. The important point is that calling user.sayName() doesn't make the arrow's this become user. Use method shorthand or a regular function when the method needs its receiver as this.

Why arrows are useful in callbacks

Array methods often use arrows because the callback usually works with its arguments and doesn't need its own this:

const prices = [5, 10, 15];
const doubled = prices.map((price) => price * 2);

console.log(doubled); // [10, 20, 30]

Arrows can also preserve the surrounding this inside a regular method:

const timer = {
  seconds: 0,
  start() {
    setTimeout(() => {
      this.seconds += 1;
      console.log(this.seconds);
    }, 500);
  },
};

timer.start(); // 1, after the timer runs

The arrow callback inherits this from start, where this is timer. If we used a regular callback function here, its this would be determined by how the timer API calls it, not by the timer object.

When a regular function is the better choice

Use a regular function when you need this to be determined by the call site, such as an object method or a DOM event handler that uses this for the element:

<button id="save-button">Save</button>

<script>
  const button = document.querySelector("#save-button");

  button.addEventListener("click", function (event) {
    console.log(this === event.currentTarget); // true
  });
</script>

For browser event listeners, a regular function's this is the element handling the event. An arrow function instead inherits this from the surrounding scope. You can still use an arrow if you prefer event.currentTarget or don't need the element as this.

Regular functions can also be called with new as constructors. Arrow functions cannot:

function Person(name) {
  this.name = name;
}

const person = new Person("Mina");
console.log(person.name); // Mina

Classes are the more common modern way to create this kind of object, but this shows one more difference: arrows don't have their own constructible this.

Other differences to know

Arrow functions don't have their own arguments object, and their this can't be changed with .call(), .apply(), or .bind(). Regular functions have their own arguments and can receive a this value through those methods. For beginner code, choose based on the function's role; use rest parameters such as (...items) => {} when an arrow needs to accept a variable number of arguments.

Common beginner mistakes

Using an arrow for an object method that needs this

Incorrect for this purpose:

const counter = {
  count: 0,
  increment: () => {
    this.count += 1;
  },
};

The arrow doesn't take this from counter. Correct: use method shorthand:

const counter = {
  count: 0,
  increment() {
    this.count += 1;
  },
};

Assuming arrows are only shorter regular functions

They also differ in this, arguments, and whether they can be used with new. Choose the kind based on the behavior you need, not just the number of characters.

Practice

Create an object with a name and a regular method that logs this.name. Then add a setTimeout callback inside that method: try a regular callback, then switch to an arrow and observe the difference. Finally, use an arrow with map to transform an array.

What we learned

  • Arrow functions offer concise syntax, especially for callbacks.
  • A regular function's this depends on how it is called.
  • An arrow function has no own this; it inherits from its surrounding scope.
  • Method shorthand or a regular function is usually right when an object method needs this.
  • Regular functions can be constructors; arrows cannot.

What's next?

Next, we'll focus on how this works in JavaScript and how the call site determines its value for regular functions.

Conclusion

Use arrows when a concise callback should keep the surrounding this. Use regular functions when you need a call-specific this, such as a method or certain event handlers. Once you choose based on behavior instead of style alone, the two function forms become much easier to use intentionally.

Written by

Dev Likhon

Dev Likhon

Full Stack Developer & Tech Educator

6+ years of professional development experience.

About Me
Share:

Comments

Share what you learned or ask a question.

Loading comments...