Show that changing storage in the same tab does not fire the event.
Acceptance criteria
- 1.#out should show not fired.
JavaScript Tutorial · JavaScript Storage & BOM
These 10 tasks go with the JavaScript Storage Events 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: “The storage event fires in other tabs when localStorage changes.” .
1.See it does not fire locallyexercise · easy · 10 min
Show that changing storage in the same tab does not fire the event.
Passes when: #out should show not fired.
2.Read the event detailsexercise · easy · 10 min · practice plan
Build a message from a fake storage event.
Passes when: #out should show theme: light -> dark.
3.React to one keyexercise · easy · 10 min · practice plan
Only respond when the logout key changes.
Passes when: #out should show reload this tab too.
4.Detect a full clearexercise · easy · 10 min · practice plan
Report a full clear when the key is null.
Passes when: #out should show everything was cleared.
5.Attach and check the listener typeexercise · medium · 10 min · practice plan
Confirm a storage listener was actually attached.
Passes when: #out should show attached.
6.Fix the event expected in the same tabbug fix · easy · 8 min
The storage event never fires in the tab making the change.
Passes when: #out should show not fired.
7.Fix the wrong key checkedbug fix · easy · 8 min · practice plan
The handler is looking at the wrong property name.
Passes when: #out should show reload this tab too.
8.Fix the clear check using undefinedbug fix · easy · 8 min · practice plan
A full clear sets key to null, not undefined.
Passes when: #out should show everything was cleared.
9.Fix the listener attached to storage itselfbug fix · easy · 8 min · practice plan
The event is listened for on window, not on localStorage.
Passes when: #out should show attached correctly.
10.Fix the message built with the wrong orderbug fix · easy · 8 min · practice plan
The old value should come before the new one.
Passes when: #out should show theme: light -> dark.
Between them these tasks cover storage event, Same-tab behaviour and Event details.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.