How to prevent changes to an object with `Object.freeze()`?
let sayan = {
name: 'Son Goku',
power: 9001
}
let character = Object.freeze(sayan);
character.name = 'Vegeta';
// output: { name: 'Son Goku', power: 9001 }
console.log(character)
April 12th, 2020
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.