Loading

Quipoin Menu

Learn • Practice • Grow

java-script / Spread and Rest Operator
interview

Q1. What are Spread and Rest Operators
Spread and Rest Operators use the ... syntax in JavaScript and were introduced in ES6.
  • The Spread Operator expands elements from arrays, objects, or iterables.
  • The Rest Operator collects multiple elements and stores them into a single variable.


Q2. What is the Spread Operator?
The Spread Operator is used to expand elements of an array, object, or iterable into individual elements.

Example
const numbers = [1, 2, 3];

const newNumbers = [...numbers, 4, 5];

console.log(newNumbers);

The spread operator expands the numbers array into individual values.


Q3. What are the uses of the Spread Operator?
The Spread Operator is used for:
  • Copying arrays
  • Merging arrays
  • Copying objects
  • Passing values to functions
  • Expanding iterables


Q4. What are the advantages of Spread and Rest Operators?
Advantags of Spread and Rest Operators are:
  • Shorter and cleaner syntax
  • Easy copying and merging of data
  • Flexible function arguments
  • Improves code readability
  • Reduces manual loops


Q5. Can Spread Operator be used with strings?
Yes, strings can be expanded into individual characters.

Example
const text = "Hello";

const letters = [...text];

console.log(letters);