JavaScript Object freeze — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Object freeze lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Freeze an object
easy10 minFreeze a settings object, try to change it, and show the value stayed put.
- 2
Check whether it is frozen
easy10 minShow whether a frozen object reports as frozen.
- 3
Show const is not enough
easy10 minChange a property on a const object and show the new value.
- 4
Seal an object
easy10 minSeal an object, change a value, try to add one, and show how many properties there are.
- 5
Show freezing is shallow
medium10 minFreeze an object with a nested object, change the nested value, and show it.
Find the bug(5)
- 1
Fix the object that was not frozen
easy8 minconst alone does not stop the property being changed.
- 2
Fix the freeze result thrown away
easy8 minfreeze returns the object, and the returned value was ignored.
- 3
Fix seal used where freeze is needed
easy8 minA sealed object still allows its values to change.
- 4
Fix freeze used where seal is needed
easy8 minThe value should still be editable, but new properties must be refused.
- 5
Fix the nested value left unprotected
easy8 minFreezing only locks the top level, so the nested host still changed.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace