Answers for "javascript object read only"

0

javascript object read only

var person = {name: 'bob', age: 30}

// This sets the name to be read only
Object.defineProperty( person, 'name', {
   value: "bob",
   writable: false,
});

// This sets the age to be writable
Object.defineProperty( person, 'name', {
   value: "age",
   writable: true,
});

person.name = 'tim' // this will NOT work
peron.age = 40 // this will work
Posted by: Guest on February-18-2021

Code answers related to "javascript object read only"

Code answers related to "Javascript"

Browse Popular Code Answers by Language