Skip to main content Accessibility Feedback

Objects

Object.freeze()

Make an object or array itself immutable. Pass the array or object in as an argument. Once run, you can’t add, update, or delete items or properties from the array or object.

let wizard = {
	name: 'Merlin',
	age: 'old AF'
};

// Freeze the wizard object
Object.freeze(wizard);

// Try to make updates
// This will not work
wizard.age = 42;
wizard.wand = true;
delete wizard.name;

// logs {name: "Merlin", age: "old AF"}
console.log(wizard);

Preorder my new course on Web Components! Want to learn how to build Web Components from scratch, master best practices, and more? Preorder today and get $100 off of the launch price.


Find this useful? You can support my work by purchasing an annual membership.