DEV Community

Discussion on: Obtaining immutable operations with native ES6 function.

Collapse
 
joelnet profile image
JavaScript Joel

Object.assign is a great way to create shallow copies of an object. You can also combine this technique with Object.freeze if you want to force immutability.

var m = Object.freeze([2, 5])
m.push(6)
// > ERROR: Can't add property 2, object is not extensible.

Collapse
 
olivermensahdev profile image
Oliver Mensah

Ok. Great