In what locations we can use the spread operator and rest operator, and how it works
javascript spread operator rest operator
Basically spread operators and rest operators syntax are same but serve different purposes.
Spread operator:-The spread operator expands elements of an iterable (like an array or object) into individual elements.
Ex:- const arr1 = [1, 2, 3];
const arr2 = [...arr1, 4, 5, 6];
console.log(arr2); // Outputs: [1, 2, 3, 4, 5, 6]
Rest operator:-The rest operator collects multiple elements into a single array or object. It is often used for function parameters to handle a variable number of arguments.
Ex:-const [first, ...rest] = [1, 2, 3, 4];
console.log(first); // Outputs: 1
console.log(rest); // Outputs: [2, 3, 4
]
Test your knowledge with interactive quizzes.
Prepare for interviews with curated question sets.
Ask your coding-related doubts and get answers.
Earn certifications to enhance your resume.
Hands-on projects to improve your skills.
Test your knowledge with interactive quizzes.
Prepare for interviews with curated question sets.
Add your technical blogs and read technical topics.
Earn certifications to enhance your resume.
Hands-on projects to improve your skills.