JS Guide
HomeQuestionsSearchResources
Search

Built for developers preparing for JavaScript, React & TypeScript interviews.

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionsjavascript
Prev
javascript
junior
functions

What is the difference between arrow functions and regular functions?

functions
arrow-functions
this
es6
fundamentals
Quick Answer

Arrow functions have a shorter syntax, don't have their own 'this' binding (they inherit from the enclosing scope), cannot be used as constructors, and don't have access to the 'arguments' object.

Detailed Explanation

Arrow functions (ES6) differ from regular functions in several ways:

Syntax:

  • Arrow functions have a concise syntax
  • Can omit parentheses for single parameter
  • Can omit braces and return for single expression

'this' binding:

  • Regular functions: 'this' depends on how the function is called
  • Arrow functions: 'this' is lexically bound (inherited from enclosing scope)

Cannot be used as constructors:

  • Arrow functions cannot be used with 'new' keyword
  • They don't have a [[Construct]] method

No arguments object:

  • Arrow functions don't have their own 'arguments' object
  • Use rest parameters (...args) instead

No prototype:

  • Arrow functions don't have a prototype property

Code Examples

Syntax comparison
// Regular function
function add(a, b) {
  return a + b;
}

// Arrow function variations
const add1 = (a, b) => { return a + b; };
const add2 = (a, b) => a + b;  // implicit return
const double = n => n * 2;      // single param, no parens
const greet = () => 'Hello!';   // no params

Real-World Applications

Use Cases

Array Method Callbacks

Arrow functions provide concise syntax for map, filter, reduce: arr.map(x => x * 2)

Event Handlers in Classes

Arrow functions preserve 'this' context when used as class method callbacks

Promise Chains

Cleaner async code with .then(data => processData(data)) syntax

Object Methods

Regular functions needed when dynamic 'this' binding is required for method calls

Mini Projects

This Binding Playground

intermediate

Build an interactive demo showing 'this' behavior in different function contexts

Function Refactoring Exercise

beginner

Practice converting callback-heavy code to clean arrow function chains

Industry Examples

React

Functional components and hooks extensively use arrow functions for callbacks and handlers

Node.js/Express

Arrow functions in route handlers; regular functions for middleware needing 'this'

Array.prototype

Built-in methods like map, filter, forEach designed to work elegantly with arrow callbacks

Resources

MDN - Arrow function expressions

docs

JavaScript.info - Arrow functions

article

Related Questions

How does the 'this' keyword work in JavaScript?

mid
this

What is a closure in JavaScript and why are they useful?

mid
closures
Previous
What is the difference between == and === in JavaScript?