Object spread operator in JavaScript

Object Spread syntax ... allows an iterable such as an array expression or string to be expanded in places.

With ES9, you can officially use this syntax.

const SAMSUNG_NEW = {
  mobile: "Galaxy S21",
  watch: "Galaxy Watch3",
  flod: "Z Flod",
};

const { mobile, ...others } = SAMSUNG_NEW;

console.log(mobile);
console.log(...others.flod);
console.log(...others.watch);
Galaxy S21
Z Flod
Galaxy Watch3
const arr = [1, 2, 3];

function sum(a, b, c) {
  return a + b + c;
}

console.log(sum(...arr));
6

Leave a Reply

Your email address will not be published.

ANOTE.DEV