# Arrow Functions vs Regular Functions

> What are arrow functions in JavaScript, and how do they differ from regular functions?

Canonical: https://www.internhack.in/learn/interview/javascript-interview/js-arrow-functions
Last updated: 2026-11-28

Difficulty: Beginner

## Question

What are arrow functions in JavaScript, and how do they differ from regular functions?

## Answer

Arrow functions (ES2015) are a shorter function syntax, `(a, b) => a + b`, that also behave differently from regular functions. Most importantly, an arrow function has no `this` of its own: it uses the `this` of the surrounding scope at the point where it is defined. Arrows also have no `arguments` object, cannot be used as constructors with `new`, and have no `prototype` property.

### Syntax shortcuts

- One parameter needs no parentheses: `x => x * 2`.
- An expression body returns implicitly: `(a, b) => a + b`.
- A block body needs an explicit `return`: `(a, b) => { return a + b; }`.
- Returning an object literal needs parentheses: `() => ({ ok: true })`. Without them, the braces are read as a block and the function returns `undefined`.

### The real difference: lexical this

A regular function's `this` is decided by how it is called (`obj.method()`, `new Fn()`, `fn.call(x)`, or a plain call). An arrow function's `this` is fixed when it is created and copied from the enclosing scope. `call`, `apply` and `bind` cannot change it.

This is why arrows are ideal for callbacks inside methods. Before ES2015, people wrote `var self = this` or `.bind(this)` to keep access to the object inside a `setTimeout` or `forEach`. With an arrow, the callback simply sees the method's `this`.

### Side-by-side comparison

| Feature | Regular function | Arrow function |
| --- | --- | --- |
| `this` | Set by the call site | Inherited from enclosing scope |
| `arguments` | Available | Not available; use `...args` |
| `new` | Allowed (function declarations/expressions) | TypeError |
| `prototype` property | Yes | No |
| Hoisting (declarations) | Fully hoisted | Behaves like the variable it is assigned to |
| Duplicate parameter names in sloppy mode | Allowed | SyntaxError |
| Can be a generator | Yes (`function*`) | No |

### When not to use an arrow

- Object methods that use `this`: `const counter = { n: 0, inc: () => this.n++ }` does not work, because `this` is the outer scope (the module or `undefined`), not `counter`. Use method shorthand: `inc() { this.n++; }`.
- Prototype methods and constructors.
- DOM event handlers where you want `this` to be the element (`function () { this.classList.toggle('open') }`). With an arrow, use `event.currentTarget` instead.
- When you need `arguments` or a generator.

### Where arrows shine

Array callbacks (`items.map(i => i.price)`), promise chains, React function components and handlers, and class fields like `handleClick = () => { ... }` in class components, which give each instance a bound handler. Note that class-field arrows are created per instance, so they cost a little more memory than prototype methods.

**Arrow functions and this. An arrow has no this of its own. Try other call styles: none of them can change it.**

1. **Arrow check comes first**: If the function is an arrow, this is taken from the scope where it was written.
2. **call, apply and bind are ignored**: Passing admin to .call() does not change an arrow's this.
3. **new throws**: Arrows are not constructors, so new on an arrow is a TypeError.
4. **Regular functions differ**: A function expression gets this from the call site: method call, explicit binding or the default rule.

## Code examples

### Lexical this in callbacks vs methods

```
const timer = {
  seconds: 0,
  start() {
    // arrow inherits this from start(), which is timer
    [1, 2, 3].forEach(() => { this.seconds++; });
    return this.seconds;
  },
  broken: () => typeof this, // arrow as a method: this is NOT timer
};

console.log(timer.start());
console.log(timer.broken());
```

Inside start, the arrow callback sees timer as this. The broken arrow method takes this from the module scope instead (module.exports in CommonJS, undefined in ESM), so it never refers to timer.

### arguments, new and object literals

```
function regular() { return arguments.length; }
const arrow = (...args) => args.length;   // use rest instead of arguments
console.log(regular(1, 2, 3), arrow(1, 2, 3));

const makeUser = (name) => ({ name, active: true }); // parens around object
console.log(makeUser('Kiran'));

const Arrow = () => {};
try { new Arrow(); } catch (e) { console.log(e.constructor.name); }
console.log(Arrow.prototype);
```

Arrows have no arguments object, need parentheses to return an object literal, and cannot be called with new because they have no prototype.

## Key points

- Arrow functions take this from the enclosing scope; call/apply/bind cannot change it
- No arguments object; use rest parameters
- Cannot be used with new and have no prototype
- Wrap object literals in parentheses for implicit return
- Avoid arrows for object methods and prototype methods that need this

## Common follow-up questions

- What does this refer to inside an arrow function defined at the top level of a module?
- Why were class-field arrow functions popular in React class components?
- Can you bind an arrow function? What happens?
- How do arrow functions affect hoisting compared to function declarations?

## Interview tips

- Do not stop at 'shorter syntax'; the lexical this is the answer they are looking for
- Give one case where an arrow is wrong, such as an object method
- Mention the object literal parentheses gotcha; it is a common practical bug

## Concepts covered

Arrow Functions, Lexical this, arguments Object, Constructors, Implicit Return

Previous: [== vs === Equality Operators](https://www.internhack.in/learn/interview/javascript-interview/js-equality-operators) · Next: [Template Literals & String Interpolation](https://www.internhack.in/learn/interview/javascript-interview/js-template-literals) · [All of JavaScript Interview](https://www.internhack.in/learn/interview/javascript-interview)

## More JavaScript Interview questions

- [null vs undefined](https://www.internhack.in/learn/interview/javascript-interview/js-null-undefined)
- [JSON: parse, stringify & Common Pitfalls](https://www.internhack.in/learn/interview/javascript-interview/js-json-parse-stringify)
- [Closures & Lexical Scope](https://www.internhack.in/learn/interview/javascript-interview/js-closures-interview)
- [Hoisting & Temporal Dead Zone](https://www.internhack.in/learn/interview/javascript-interview/js-hoisting-interview)
- [Object Methods & Property Descriptors](https://www.internhack.in/learn/interview/javascript-interview/js-object-methods)
- [this Keyword & Binding Rules](https://www.internhack.in/learn/interview/javascript-interview/js-this-keyword)

## Related

- [Learn](https://www.internhack.in/learn)
- [Interview Prep](https://www.internhack.in/learn/interview)
- [JavaScript Interview](https://www.internhack.in/learn/interview/javascript-interview)
