Hackforge Academy

Category: javascript

spread operator

Published on 16 Jul 2026

Explanation

The spread operator (...) expands arrays or objects into individual elements.

Code:

const arr1 = [1,2];
const arr2 = [...arr1,3,4];

Explanation

Spread is commonly used to copy arrays.

Code:

const copy = [...arr1];

Explanation

Spread merges multiple objects together.

Code:

const user = {name:'John'};
const info = {...user, age:25};

Explanation

The rest operator collects multiple values into a single array.

Code:

function sum(...numbers) {
  console.log(numbers);
}

Explanation

Rest is useful for functions with variable numbers of arguments.

Code:

sum(10,20,30);

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