Skip to main content

JavaScript Storage Events — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Storage Events 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

    See it does not fire locally

    easy10 min

    Show that changing storage in the same tab does not fire the event.

  2. 2

    Read the event details

    easy10 min

    Build a message from a fake storage event.

  3. 3

    React to one key

    easy10 min

    Only respond when the logout key changes.

  4. 4

    Detect a full clear

    easy10 min

    Report a full clear when the key is null.

  5. 5

    Attach and check the listener type

    medium10 min

    Confirm a storage listener was actually attached.

Find the bug(5)

  1. 1

    Fix the event expected in the same tab

    easy8 min

    The storage event never fires in the tab making the change.

  2. 2

    Fix the wrong key checked

    easy8 min

    The handler is looking at the wrong property name.

  3. 3

    Fix the clear check using undefined

    easy8 min

    A full clear sets key to null, not undefined.

  4. 4

    Fix the listener attached to storage itself

    easy8 min

    The event is listened for on window, not on localStorage.

  5. 5

    Fix the message built with the wrong order

    easy8 min

    The old value should come before the new one.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace