javascript object read only

Solutions on MaxInterview for javascript object read only by the best coders in the world

showing results for - "javascript object read only"
Federico
23 Jul 2019
1var person = {name: 'bob', age: 30}
2
3// This sets the name to be read only
4Object.defineProperty( person, 'name', {
5   value: "bob",
6   writable: false,
7});
8
9// This sets the age to be writable
10Object.defineProperty( person, 'name', {
11   value: "age",
12   writable: true,
13});
14
15person.name = 'tim' // this will NOT work
16peron.age = 40 // this will work