The three dots operator

This operator (...) helps you achieve many things that previously required many lines of code, unfamiliar syntax, and more.

The three dots operator has two different meanings in JavaScript. The syntax is very similar, but you use each one in different contexts. These two different uses of the ... are the spread and rest operators

The spread Operator

const newArray = ['firstItem', ...oldArray];

Let's now look at various instances in which we can use the spread operator.

Copy an array into a new array without affecting the original array
let studentNames = ["Daniel", "Jane", "Joe"]
let names = [...studentNames]
Copy an Object With the Spread Operator
let user = { name: "John Doe", age: 10 };
let copiedUser = { ...user };
console.log(copiedUser); // { name: "John Doe", age: 10 }