InterviewHubPRO
Section Overview
Q49

Question 49 of 521

Part 1: Core Objects, Prototypes, Functions & Scope (1 - 53)

9%
JavaScript Internals (521 Qs)•Part 1: Core Objects, Prototypes, Functions & Scope (1 - 53)

What is a storage event and its event handler

The StorageEvent is an event that fires when a storage area has been changed in the context of another document. Whereas onstorage property is an EventHandler for processing storage events. The syntax would be as below

javascript
window.onstorage = functionRef;

Let's take the example usage of onstorage event handler which logs the storage key and it's values

javascript
window.onstorage = function (e) {
  console.log(
    "The " +
      e.key +
      " key has been changed from " +
      e.oldValue +
      " to " +
      e.newValue +
      "."
  );
};