Hackforge Academy

Category: javascript

Arrow functions

Published on 29 Jun 2026

Explanation

Arrow functions provide a shorter syntax for writing functions and were introduced in ES6.

Code:

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

Explanation

Arrow functions with a single parameter do not require parentheses around the parameter.

Code:

const square = x => x * x;
console.log(square(5));

Explanation

Arrow functions can have multiple parameters enclosed in parentheses.

Code:

const add = (a, b) => a + b;
console.log(add(10, 20));

Explanation

Arrow functions are commonly used as callback functions with array methods like map() and filter().

Code:

const numbers = [1, 2, 3];
const doubled = numbers.map(num => num * 2);

Explanation

Unlike regular functions, arrow functions do not have their own 'this' value and inherit it from the surrounding scope.

Code:

const person = {
  name: 'John',
  greet() {
    setTimeout(() => {
      console.log(this.name);
    }, 1000);
  }
};

๐Ÿš€ 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