How to prevent changes to an object with `Object.freeze()`?

let sayan = {
  name: 'Son Goku',
  power: 9001

let character = Object.freeze(sayan); = 'Vegeta';

// output: { name: 'Son Goku', power: 9001 }

April 12th, 2020

# Object.freeze() - How to prevent changes to an object?

Add to bookmarks

Object.freeze() can prevent changes to an object. If you're in strict mode (use strict; in the first line of your code), your browser will throw an error.