0Pricing
JavaScript Academy · Lesson

Object.freeze and seal

Prevent changes to objects.

Why Freeze Objects?

Immutability means data cannot change after creation. It prevents accidental mutations, makes code easier to reason about, and avoids whole classes of bugs.

JavaScript gives you Object.freeze and Object.seal to lock objects down.

Object.freeze Basics

Object.freeze makes an object fully read-only: you cannot add, remove, or change properties. It returns the same object, now frozen.

const user = Object.freeze({ name: 'Ada', age: 36 });
user.age = 99;
console.log(user.age);

All lessons in this course

  1. Object.freeze and seal
  2. Shallow vs Deep Freezing
  3. Immutable Update Patterns
  4. structuredClone for Deep Copies
← Back to JavaScript Academy