🎯Arrow Functions vs. Regular Functions in JavaScript

Published: (January 11, 2026 at 09:00 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Cover image for 🎯Arrow Functions vs. Regular Functions in JavaScript

One of the most common sources of confusion in JavaScript interviews is how this behaves differently in arrow functions vs. regular functions. If you’ve ever wondered why this prints undefined sometimes — this guide will finally make it clear.

1️⃣ Regular Functions — this is Dynamic

In regular functions, the value of this depends on how the function is called, not where it is defined.

const user = {
  name: 'Richa',
  greet: function () {
    console.log(this.name);
  }
};

user.greet(); // Richa

const greetCopy = user.greet;
greetCopy(); // ❌ undefined (or window.name in browsers)

Why this happens
this is determined by the call context. When the function loses its object reference, this no longer points to user.

2️⃣ Arrow Functions — this is Lexical

Arrow functions do not have their own this. Instead, they inherit this from the surrounding scope.

const user = {
  name: 'Richa',
  greet: () => {
    console.log(this.name);
  }
};

user.greet(); // ❌ undefined

Why?
The arrow function was created in the global scope, so it inherits the global this, not the user object.

✅ Correct Approach

Use a regular method when you need this to refer to the object:

const user = {
  name: 'Richa',
  greet() {
    console.log(this.name);
  }
};

user.greet(); // ✅ Richa

3️⃣ Best Use Case: Arrow Functions Inside Regular Functions

Arrow functions shine when used inside methods or callbacks, because they keep the same this context.

const team = {
  name: 'Frontend',
  members: ['Richa', 'Jane'],
  showMembers() {
    this.members.forEach(member => {
      console.log(`${member} is part of ${this.name}`);
    });
  }
};

team.showMembers();
// Richa is part of Frontend
// Jane is part of Frontend

If a regular function were used inside forEach, this.name would be undefined.

Interview-Ready Answer

  • Regular functions have a dynamic this — it depends on how they are called.
  • Arrow functions have a lexical this — they inherit it from the parent scope.

🎯 Extra Tip

This is why arrow functions are commonly used in React components, where you want this to stay consistent.

Key Takeaway

Arrow functions aren’t just a shorter way to write code — they preserve context.

FeatureRegular FunctionArrow Function
Has its own this✅ Yes❌ No
this depends on call site✅ Yes❌ No
Best used for object methods✅ Yes❌ No
Best used for callbacks❌ Often No✅ Yes

Final Thought

Once you understand the difference between dynamic vs. lexical this, your code becomes:

  • Cleaner ✅
  • Easier to reason about ✅
  • Less bug‑prone ✅

Arrow functions don’t just save syntax — they save context. ⚡

Back to Blog

Related posts

Read more »

Asynchronous in JavaScript

🔴 Synchronous Normal One task mudinja apram thaan next task start aagum. javascript console.log'One'; console.log'Two'; console.log'Three'; 👉 Output One Two...

Function, Objects and Array In JS.

Functions A function is a block of code that performs a specific task and can be reused. There are three ways to define a function in JavaScript: 1. Function D...