bhylu.com

Advertisements

JS 2018

Object spread copies own enumerable fields. It makes small record updates readable without mutating the original top-level object.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const original = {title: "Repair club", places: 12};
const updated = {...original, places: 10};
console.log(original.places, updated.places);

What happens

The original stays 12 while the copy holds 10.