Freeze a settings object, try to change it, and show the value stayed put.
Acceptance criteria
- 1.#out should show dark.
JavaScript Tutorial · JavaScript Objects
These 10 tasks go with the JavaScript Object freeze chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “Object.freeze stops an object being changed after it is created.” .
1.Freeze an objectexercise · easy · 10 min
Freeze a settings object, try to change it, and show the value stayed put.
Passes when: #out should show dark.
2.Check whether it is frozenexercise · easy · 10 min · practice plan
Show whether a frozen object reports as frozen.
Passes when: #out should show true.
3.Show const is not enoughexercise · easy · 10 min · practice plan
Change a property on a const object and show the new value.
Passes when: #out should show light.
4.Seal an objectexercise · easy · 10 min · practice plan
Seal an object, change a value, try to add one, and show how many properties there are.
Passes when: #out should show Grace then 1.
5.Show freezing is shallowexercise · medium · 10 min · practice plan
Freeze an object with a nested object, change the nested value, and show it.
Passes when: #out should show remote.
6.Fix the object that was not frozenbug fix · easy · 8 min
const alone does not stop the property being changed.
Passes when: #out should show dark.
7.Fix the freeze result thrown awaybug fix · easy · 8 min · practice plan
freeze returns the object, and the returned value was ignored.
Passes when: #out should show true.
8.Fix seal used where freeze is neededbug fix · easy · 8 min · practice plan
A sealed object still allows its values to change.
Passes when: #out should show dark.
9.Fix freeze used where seal is neededbug fix · easy · 8 min · practice plan
The value should still be editable, but new properties must be refused.
Passes when: #out should show Grace then 1.
10.Fix the nested value left unprotectedbug fix · easy · 8 min · practice plan
Freezing only locks the top level, so the nested host still changed.
Passes when: #out should show local.
Between them these tasks cover Object.freeze, Object.seal and Immutability.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.