Skip to main content

Command Palette

Search for a command to run...

Arrow Functions in JavaScript: A Simpler Way to Write Functions

This blog explains arrow function syntax, parameters, implicit vs explicit return, and practical examples to help beginners write modern and readable JavaScript code.

Updated
β€’3 min read
Arrow Functions in JavaScript: A Simpler Way to Write Functions
P

My name is 𝐏𝐫𝐚𝐀𝐚𝐬𝐑 and I talk about 𝗧𝗲𝗰𝗡-𝐊𝐧𝐨𝐰π₯𝐞𝐝𝐠𝐞, π—ͺπ—²π—―π——π—²π˜ƒ, π——π—²π˜ƒπ—’π—½π˜€ and π—Ÿπ—Άπ—³π—²π˜€π˜π˜†π—Ήπ—².

Modern JavaScript introduced arrow functions to make writing functions shorter and cleaner.

If you're learning JS, arrow functions will quickly become your favorite feature.

Let’s understand them step by step.

❋ What Are Arrow Functions?

Arrow functions are a shorter way to write functions in JavaScript.

They were introduced in ES6 (2015) to reduce boilerplate code and improve readability.

Instead of writing:

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

We can write:

const greet = (name) => {
  return "Hello " + name;
};

❋ Basic Arrow Function Syntax

Here is the general syntax:

const functionName = (parameters) => {
  // code
};
  • const β†’ storing function in a variable

  • (parameters) β†’ input values

  • => β†’ arrow symbol

  • {} β†’ function body


❋ Arrow Function with One Parameter

If there is only one parameter, you can remove parentheses.

Normal function:

function square(num) {
  return num * num;
}

Arrow function:

const square = num => {
  return num * num;
};

❋ Arrow Function with Multiple Parameters

If there are multiple parameters, parentheses are required.

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

Example:

console.log(add(5, 3)); // 8

❋ Implicit Return vs Explicit Return

This is the most powerful feature.

πŸ”Ή Explicit Return (using return keyword)

const multiply = (a, b) => {
  return a * b;
};

πŸ”Ή Implicit Return (no return keyword)

If your function has only one expression, you can remove {} and return.

const multiply = (a, b) => a * b;

JavaScript automatically returns the value.

That’s called implicit return.


❋ Basic Difference: Normal Function vs Arrow Function

Feature Normal Function Arrow Function
Syntax Longer Shorter
this behavior Has its own this Uses parent this
Hoisting Yes No
Beginner friendly Yes Yes

❋ Why Arrow Functions Matter

  • Less boilerplate

  • Cleaner callbacks

  • Perfect for array methods like:

    • map()

    • filter()

    • reduce()

  • Modern JavaScript standard


Want More…?

I write articles on blog.prakashtsx.com and also post development-related content on the following platforms:

JavaScript

Part 2 of 15

In this series of blogs I have written some interesting concepts related to JavaScript.

Up next

JavaScript Promise Methods

A deep, real-world explanation of Promises in JavaScript you’ll remember forever.