JavaScript Spread Operator

node v14.20.0
version: 3.0.0
endpointsharetweet
Use the spread operator to create copies of immutable objects.
/* Use the spread operator to create copies of immutable objects. - https://runkit.com/stxxop/javascript-spread-operator - Notice that the spread operator is used within an object literal. - Override values as needed. */ const car1 = { make: "Ford", model: "F-150"}; console.log(car1) // {make: "Ford", model: "F-150"} const car2 = { ...car1 }; console.log(car2); // {make: "Ford", model: "F-150"} const car3 = { ...car2, model: "Mustang"}; console.log(car3); // {make: "Ford", model: "Mustang"}
Loading…

no comments

    sign in to comment