
Your Success, Our Mission!
6000+ Careers Transformed.
Explanation
The spread operator allows array elements to be passed as individual arguments to a function. Each element is expanded in order and mapped to the function’s parameters. This removes the need to manually access array indices. It improves readability when dealing with dynamic argument lists. The original array remains unchanged during the function call.
Code / Tabular Examples
function sum(a, b, c) {
return a + b + c;
}const values = [10, 20, 30];
const result = sum(...values);
Parameter | Value |
| a | 10 |
| b | 20 |
| c | 30 |
Example
Functions often expect separate parameters.
Data is frequently available as an array.
Spread bridges this mismatch cleanly.
It avoids repetitive parameter mapping code.
The function call remains concise and clear.
Use Cases
Explanation
Spread and rest use the same syntax but serve opposite roles. Spread expands values when calling a function or creating literals. Rest collects multiple values into a single array in function definitions. Spread is used at the call site, while rest is used in parameters. Understanding the distinction prevents incorrect usage.
Code / Tabular Examples
// Rest parameter
function total(...nums) {
return nums.reduce((a, b) => a + b, 0);
const numbers = [1, 2, 3];
total(...numbers);
Feature | Spread | Rest |
| Purpose | Expands values | Collects values |
| Location | Function call | Function definition |
| Result | Individual elements | Array |
Example
Spread sends multiple values into a function.
Rest gathers multiple arguments inside a function.
Mixing them up leads to logic errors.
Used correctly, they complement each other well.
Together, they enable flexible function design.
Use Cases
Top Tutorials
CNN in Deep Learning 2026
A beginner-friendly guide to CNNs: understand deep learning essentials, create Python-based models, and explore advanced applications.
Breaking The Limits: Scaling Databases with MySQL Partitioning
Learn MySQL partitioning with examples. Improve query performance, scalability, and data management using RANGE, LIST, HASH, KEY, and composite techniques.
ML in Action: Hands-On Guide to Deploying and Serving Models
Learn model deployment and serving—from concepts to real-world architectures, tools, APIs, containers, and cloud workflows for production-ready ML.
All Courses (6)
Master's Degree (2)
Fellowship (2)
Certifications (2)