Abhishek ,

Dec 14, 2025 • 1 min read

Function Declaration vs Function Expression

1️⃣ Function Declaration

A Function Declaration defines a function using the function keyword with a name.

Syntax-

function add(a, b) {
return a + b;
}
Key Points-

  • Hoisted (can be used before it is defined)

  • Has a function name

  • Commonly used for reusable logic

    Example

    console.log(add(2, 3)); // ✅ Works
    
    function add(a, b) {
     return a + b;
    }
    
    

2️⃣ Function Expression

A Function Expression assigns a function to a variable.

Syntax

const add = function(a, b) {
 return a + b;
};

Key Points

  • Not hoisted like function declarations

  • Stored in a variable

  • Can be anonymous

Example

console.log(add(2, 3)); // ❌ Error

const add = function(a, b) {
 return a + b;
};

Function Declaration vs Function Expression

3️⃣ Arrow Functions in JavaScript

What are Arrow Functions?

Arrow functions are a shorter syntax for writing function expressions.

Syntax

const add = (a, b) => a + b;

Arrow Function vs Normal Function

Normal Function

function greet(name) {
return "Hello " + name;
}

Arrow Function

const greet = name => "Hello " + name;

✨ Why Arrow Functions Are Simpler

✅ Shorter syntax
✅ No function keyword
✅ Implicit return (for single expressions)

Join Abhishek on Peerlist!

Join amazing folks like Abhishek and thousands of other builders on Peerlist.

peerlist.io/

It’s available... this username is available! 😃

Claim your username before it's too late!

This username is already taken, you’re a little late.😐

0

8

0