Hackforge Academy

Category: javascript

Arrow Function

Published on 18 Feb 2026

Explanation


Arrow function is a shorter syntax for
writing
functions in JavaScript. It was introduced in ES6
and uses the => symbol.

Code:

const greet = () => {
  console.log("Hello World");
};

greet();

Explanation


Arrow functions can take parameters. If
there is
only one parameter, parentheses are optional.

Code:

const square = x => x * x;

console.log(square(5));

Explanation


When there are multiple parameters,
parentheses are required
around them.

Code:

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

console.log(add(10, 20));

Explanation


Arrow functions can return values directly
without using
the return keyword if the function has a
single expression.

Code:

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

console.log(multiply(3, 4));

Explanation


If you use curly braces, you must
explicitly
use the return keyword.

Code:

const subtract = (a, b) => {
  return a - b;
};

console.log(subtract(10, 5));

Explanation


Arrow functions do not have their own this.
They inherit this from the surrounding lexical scope.

Code:

function Person() {
  this.age = 0;

  setInterval(() => {
    this.age++;
    console.log(this.age);
  }, 1000);
}

new Person();

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community