Difference between Regular functions and Arrow functions
Last Updated :
15 Oct, 2025
In JavaScript, functions are essential building blocks. ES6 introduced Arrow Functions, offering a shorter syntax and simpler this handling. While both regular and arrow functions achieve similar tasks, they differ in syntax, behavior, and usage.
Regular function
A regular function is defined using the function keyword and can have its own this, arguments, and prototype.
JavaScript
// Defining a regular function
function greet(name) {
console.log('Hello, ' + name + '!');
}
// Calling the function
greet('Geek');
Syntax
let x = function function_name(parameters){ // body of the function};Main Features
1. Access arguments
In regular functions, you can access all passed arguments using the arguments object, which is an array-like object containing each argument passed to the function.
JavaScript
function showArgs() {
console.log(arguments);
}
showArgs(1, 2, 3);
Output[Arguments] { '0': 1, '1': 2, '2': 3 }
2. Duplicate named parameters
In regular functions, duplicate named parameters are allowed but not recommended. The last occurrence of the parameter overwrites previous ones, and only its value is used.
JavaScript
function example(a, b, a) {
console.log(a, b);
}
example(1, 2, 3);
3. Hosting
In regular functions, function declarations are hoisted to the top of their scope, allowing them to be called before they're defined in the code.
JavaScript
greet(); // Output: Hello Geeks!
function greet() {
console.log('Hello Geeks!');
}
4. Using this keyword
In regular functions, this refers to the object that calls the function (runtime binding). Its value can vary based on how the function is called (method, event, or global).
JavaScript
const obj = {
name: 'Geeks',
greet: function() {
console.log(this.name);
}
};
obj.greet();
5. Using new keyword
Regular functions can be used as constructors with the new keyword, allowing the creation of new object instances. The new keyword sets this to the new object inside the function.
JavaScript
function Person(name) {
this.name = name;
}
const p = new Person('Geeks'); // Creates a new Person object
console.log(p.name);
Arrow function
Arrow functions in JavaScript are a concise way to define functions using the => syntax. They do not have their own this context, instead inheriting it from the surrounding scope. Arrow functions also lack their own arguments object and are ideal for shorter functions and callbacks.
javascript
// Defining an arrow function
const greet = (name) => {
console.log(`Hello, ${name}!`);
};
// Calling the function
greet('Geeks');
Syntax
let x = (parameters) => {
// body of the function
};Main Features
1. Access arguments
Arrow functions do not have their own arguments object. To access arguments in arrow functions, use rest parameters (...args) to collect all arguments into an array.
JavaScript
const showArgs = (...args) => {
console.log(args);
};
showArgs(1, 2, 3);
2. Duplicate named parameters
Arrow functions do not allow duplicate named parameters, even in non-strict mode, and will throw a syntax error if duplicates are present. Always use unique parameter names in arrow functions.
JavaScript
const example = (a, b, a) => {
console.log(a);
};
// SyntaxError: Duplicate parameter name not allowed in this context
Output:
SyntaxError: Duplicate parameter name not allowed in this context
3. Hoisting
Arrow functions are not hoisted like regular function declarations. They are treated as variables, so they cannot be called before being defined due to the temporal dead zone.
JavaScript
greet(); // ReferenceError: Cannot access 'greet' before initialization
const greet = () => {
console.log('Hello!');
};
Output:
ReferenceError: Cannot access 'greet' before initialization
4. Using this keyword
In arrow functions, this is lexically inherited from the surrounding scope, not the function itself. It maintains the this value from where the arrow function is defined.
JavaScript
const obj = {
name: 'Geeks',
greet: () => {
console.log(this.name);
}
};
obj.greet(); // Output: undefined (inherited from outer scope)
5. Using new keyword
Arrow functions cannot be used as constructors and do not support the new keyword. Attempting to use new with an arrow function will result in a TypeError.
javascript
const Person = () => {};
const p = new Person(); // TypeError: Person is not a constructor
Output:
TypeError: Person is not a constructor
Difference table of Regular functions and Arrow functions
| Feature | Regular Functions | Arrow Functions |
|---|
| Syntax | Defined using the function keyword. | Uses concise => syntax. |
this Binding | this depends on the calling context. | Inherits this from the surrounding scope. |
| Arguments Object | Has its own arguments object. | Does not have its own arguments object. |
| Constructor Usage | Can be used as a constructor with new. | Cannot be used as a constructor. |
| Hoisting | Function declarations are hoisted. | Not hoisted; behaves like variables. |
| Implicit Return | Requires return for returning values. | Supports implicit return for single expressions. |
| Methods as Object Properties | Suitable for object methods with proper this. | Not suitable for methods due to lexical this. |
Explore
JavaScript Basics
Array & String
Function & Object
OOP
Asynchronous JavaScript
Exception Handling
DOM
Advanced Topics