Skip to content
jshacks.dev
Functions

Arrow Functions vs Regular Functions

Arrow functions vs regular functions compared on this, arguments, new, prototype, hoisting and class fields, with exact output and a rule for choosing.

6 min read
Summarize in AI
Flat illustration of two options weighed side by side, with the JavaScript, Node.js and npm logos.

An arrow function is not a shorter regular function. It is a different kind of function with fewer capabilities, and the main difference is that it has no this of its own: it uses the this of the code around it, fixed at the moment it was written. That single fact makes arrows the right choice for callbacks inside methods, and the wrong choice for methods themselves. The other differences follow from the same idea that an arrow is a plain function value and not a full function object: it has no arguments, it cannot be called with new, it has no prototype, it cannot be a generator, and call, apply and bind cannot change its this. This post compares the two on each point with exact output, covers the syntax trap of returning an object literal, the way that class fields use arrows to keep this, and ends with a rule for choosing. The examples run as an ES module on Node.js 24, where the this of the module's top level is undefined.

The value of this

A regular function gets its this from how it is called. An arrow function gets it from where it is defined.

JavaScript
const user = {
  name: "Ada",
  regular() {
    return this.name;
  },
  arrow: () => typeof this,
  delayed() {
    return [1, 2].map(() => this.name);
  },
  delayedRegular() {
    return [1, 2].map(function () {
      return typeof this;
    });
  },
};

console.log(user.regular(), user.arrow());
console.log(user.delayed());
console.log(user.delayedRegular());
Text
Ada undefined
[ 'Ada', 'Ada' ]
[ 'undefined', 'undefined' ]

The method written with the regular syntax has this set to user, because it was called as user.regular(). The arrow property took the this of the module's top level, which is undefined, so typeof this is the string "undefined" and not the object. This is the trap: an arrow as an object method does not see the object. Inside a method, though, an arrow callback keeps the method's this, as the delayed method shows, and a regular function callback has its own this, which is undefined in strict mode and in modules. That is the situation arrows were made for: a callback that must see the this of the method around it.

Losing this

A regular method that is detached from its object loses this. An arrow does not have one to lose, which sounds like an advantage and only works when the arrow was created in the right place.

JavaScript
const detached = user.regular;

try {
  detached();
} catch (error) {
  console.log(error.name);
}

class Button {
  label = "OK";
  method() {
    return this.label;
  }
  handler = () => this.label;
}

const { method, handler } = new Button();

console.log(handler());
try {
  method();
} catch (error) {
  console.log(error.name);
}
Text
TypeError
OK
TypeError

Calling the detached method gives a TypeError, since this is undefined and this.name reads a property of it. In the class, handler is a field whose value is an arrow function created inside the constructor, so its this is the new instance, and it still works when it is pulled out of the object, as event handlers and callbacks are. The ordinary method fails in the same way. That is the main use of an arrow as a class field: a handler that is passed around and must know its object. The cost is that every instance has its own copy of the function, where a method is shared on the prototype.

arguments and rest parameters

A regular function has an arguments object with all of its arguments. An arrow does not have one, and an arguments inside an arrow refers to the enclosing function's, or is an error at the top of a module. The replacement is a rest parameter, which works in both.

JavaScript
function regular() {
  return arguments.length;
}
const rest = (...args) => args.length;

console.log(regular(1, 2, 3), rest(1, 2, 3));

try {
  (() => arguments)();
} catch (error) {
  console.log(error.name);
}
Text
3 3
ReferenceError

Both count three arguments. The rest parameter is an ordinary array, with map and length, while arguments is an array-like object, so rest is the better tool in both kinds of function. The arrow's use of arguments is a ReferenceError here because the module top level has no such name.

Construction and the prototype

A regular function can be called with new and has a prototype property. An arrow can do neither.

JavaScript
function Point(x) {
  this.x = x;
}
const arrowPoint = (x) => ({ x });

console.log(new Point(3).x, typeof Point.prototype, typeof arrowPoint.prototype);

try {
  new arrowPoint(3);
} catch (error) {
  console.log(error.name);
}
Text
3 object undefined
TypeError

A function used as a constructor needs to be a regular function or, better, a class. An arrow has no prototype, and new on it throws a TypeError. Arrows are for functions that compute and return, not for functions that build objects with new.

Hoisting

A function declaration is hoisted with its body, so it can be called before the line where it is written. An arrow stored in a const is a variable like any other, and it exists only after its line has run.

JavaScript
console.log(hoisted(2));

function hoisted(n) {
  return n * 2;
}

try {
  early(2);
} catch (error) {
  console.log(error.name);
}

const early = (n) => n * 2;
Text
4
ReferenceError

The declaration works from anywhere in its scope. The arrow is in its temporal dead zone until its const line, and calling it earlier throws. Some teams use declarations for top-level functions for that reason, so that the main logic can come first and the helpers after it.

Returning an object literal

An arrow with a single expression returns its value without return. A pair of braces after the arrow starts a block body and not an object, so an object literal must be wrapped in parentheses.

JavaScript
const wrapped = () => ({ ok: true });
const block = () => {
  ok: true;
};

console.log(wrapped(), block());
Text
{ ok: true } undefined

The second function has a block body that contains a label named ok followed by the expression true, a legal statement, so it returns undefined. This is a quiet bug in code that maps items to objects, and the fix is the parentheses.

call, apply and bind

For a regular function, call, apply and bind set this. For an arrow they have no effect on this, since it is fixed.

JavaScript
function whoRegular() {
  return this.id;
}
const whoArrow = () => typeof this;

console.log(whoRegular.call({ id: 7 }), whoArrow.call({ id: 7 }), whoArrow.bind({ id: 7 })());
Text
7 undefined undefined

The regular function reads the id of the object it was called with. The arrow ignores both call and bind, and reports the this of the module. Bind can still fix arguments in an arrow, and cannot fix this.

Names, generators and syntax

An arrow assigned to a variable gets that name, which shows in stack traces, and an arrow passed inline is anonymous. Generators must be regular functions, written with function*, and an arrow cannot be a generator or use yield. An arrow cannot have duplicate parameter names, and it can be an async arrow. A regular function expression can name itself for recursion and for readable stack traces, which an arrow cannot do without a variable.

Choosing

You needUse
A short callback inside a method that uses thisAn arrow
An object method that uses thisA method with the regular syntax
A class method shared across instancesA normal method
A class handler passed aroundAn arrow class field
A constructorA class, or a regular function
A generatorfunction*
A top-level helper called before it is definedA function declaration
A one-expression transformationAn arrow

Practical rules we follow

Use arrows for callbacks and one-expression functions. Use methods, not arrow properties, in objects and classes. Use rest parameters and never arguments. Wrap an object literal return in parentheses. Use declarations when you want hoisting. And write down why, when a class field is an arrow.

Where this comparison stops

Arrows are not faster or slower for any reason that matters in application code, and no guidance here depends on speed. The this rules assume strict mode, which modules and classes use, and in sloppy scripts a detached regular function gets the global object as its this, which hides some of these errors. Frameworks that rely on this being rebound, such as some older component systems, need regular functions. The function forms are documented on MDN.

Taggedfunctions
Share

Keep reading

Flat illustration of two options weighed side by side, with the JavaScript, Vite and Node.js logos.
Functions

Classes vs Factory Functions

Classes vs factory functions in JavaScript compared on private state, this, instanceof, inheritance, memory, JSON and testing, with exact output.

7 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.