JavaScript › Browser Storage & Web APIs

What is the storage event and when does it fire?

Intermediate

Answer

The storage event fires on window in OTHER tabs/windows of the same origin whenever localStorage changes — it never fires in the tab that made the change itself. It's useful for keeping multiple open tabs in sync.
window.addEventListener('storage', (e) => {
  console.log(e.key, e.oldValue, e.newValue);
});
Real-world example Logging a user out in every open tab the instant they log out in one tab.

Common follow-ups: Does sessionStorage also trigger the storage event?