MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Rest & Spread Operators0%
Study Materials
JavaScript for IntermediateProgress 0%
1.1Block Scope with let & const1.2Template Literals1.3Destructuring Arrays and Objects1.4Default Parameters1.5Enhanced Object Literals
2.1Arrow Functions Advanced2.2Rest & Spread Operators2.3Closures Introduction2.4Immediately Invoked Functions (IIFE)
HomeTutorialsJavaScript for IntermediateRest & Spread Operators
Closures Introduction

Rest & Spread Operators

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

Rest and Spread Operators (...)

The three dots (...) in modern JavaScript are used for two distinct, powerful features depending on context: the Rest Parameter (collecting items into an array) and the Spread Operator (unpacking items from an iterable).


1. Rest vs. Spread: The Core Difference

Visual Architecture Blueprint
+-----------------------------------------------------------------------------+
| REST PARAMETER (Collects multiple items into ONE single array)              |
| Context: In function parameter lists or destructuring patterns              |
| Example: function sum(...numbers) { ... }                                  |
+-----------------------------------------------------------------------------+
                                     vs.
+-----------------------------------------------------------------------------+
| SPREAD OPERATOR (Expands ONE array/object into individual elements)         |
| Context: In function calls, array literals, or object literals             |
| Example: Math.max(...numbers)  |  [...arr1, ...arr2]                       |
+-----------------------------------------------------------------------------+

2. The Spread Operator in Action

A. Combining and Cloning Arrays (Shallow Copy)

1const frontend = ["HTML", "CSS", "JS"];
2const backend = ["Node.js", "Express", "MongoDB"];
3 
4// Combining arrays cleanly:
5const fullStack = [...frontend, ...backend, "Git"];
6console.log(fullStack);
7// ["HTML", "CSS", "JS", "Node.js", "Express", "MongoDB", "Git"]
8 
9// Cloning an array (avoids mutating original):
10const clonedFrontend = [...frontend];
11clonedFrontend.push("React");
12console.log(frontend); // ["HTML", "CSS", "JS"] (Untouched!)

B. Spreading into Function Arguments:

1const scores = [88, 94, 72, 99, 81];
2 
3// Math.max expects numbers, not an array:
4console.log(Math.max(...scores)); // 99 (Unpacked into 88, 94, 72, 99, 81)

C. Spreading and Merging Objects:

1const defaultSettings = { theme: "dark", notifications: true, fontSize: 14 };
2const userPreferences = { fontSize: 16, notifications: false };
3 
4// Merge: userPreferences override defaultSettings!
5const finalConfig = { ...defaultSettings, ...userPreferences };
6console.log(finalConfig);
7// { theme: "dark", notifications: false, fontSize: 16 }

3. The Rest Parameter in Action

A. Gathering Remaining Function Arguments:

1function awardMedals(gold, silver, ...bronzeRunners) {
2 console.log(`🥇 Gold: ${gold}`);
3 console.log(`🥈 Silver: ${silver}`);
4 console.log(`🥉 Bronze Runners:`, bronzeRunners);
5}
6 
7awardMedals("Sumit", "Neha", "Aarav", "Rahul", "Pooja");
8// Bronze Runners: ["Aarav", "Rahul", "Pooja"]

B. Rest in Array and Object Destructuring:

1// Array Rest:
2const [first, second, ...remaining] = [10, 20, 30, 40, 50];
3console.log(remaining); // [30, 40, 50]
4 
5// Object Rest:
6const student = { id: 1, name: "Sumit", marks: 95, city: "Delhi" };
7const { id, ...details } = student;
8console.log(details); // { name: "Sumit", marks: 95, city: "Delhi" }

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What is the primary difference between the Rest operator and the Spread operator?
Question 2
How do you create a shallow copy of an array original using Spread?
Question 3
Where must the Rest parameter (...rest) be placed in a function's parameter list?
Question 4
If const obj1 = { a: 1, b: 2 }; const obj2 = { b: 99, c: 3 }; const merged = { ...obj1, ...obj2 };, what is the value of merged.b?
Question 5
What does [..."MSK"] evaluate to?
Next Lesson

Closures Introduction

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Arrow Functions AdvancedClosures Introduction

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Intermediate with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext