Skip to main content

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. 1

    Freeze an object

    easy10 min

    Freeze a settings object, try to change it, and show the value stayed put.

  2. 2

    Check whether it is frozen

    easy10 min

    Show whether a frozen object reports as frozen.

  3. 3

    Show const is not enough

    easy10 min

    Change a property on a const object and show the new value.

  4. 4

    Seal an object

    easy10 min

    Seal an object, change a value, try to add one, and show how many properties there are.

  5. 5

    Show freezing is shallow

    medium10 min

    Freeze an object with a nested object, change the nested value, and show it.

Find the bug(5)

  1. 1

    Fix the object that was not frozen

    easy8 min

    const alone does not stop the property being changed.

  2. 2

    Fix the freeze result thrown away

    easy8 min

    freeze returns the object, and the returned value was ignored.

  3. 3

    Fix seal used where freeze is needed

    easy8 min

    A sealed object still allows its values to change.

  4. 4

    Fix freeze used where seal is needed

    easy8 min

    The value should still be editable, but new properties must be refused.

  5. 5

    Fix the nested value left unprotected

    easy8 min

    Freezing 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