We want mechanisms that persist data between page loads (i.e., after refresh or navigation), in the browser.
A. localStorage
Part of the Web Storage API.
Data persists across page reloads and browser restarts (until explicitly cleared).
Scoped per origin (protocol + host + port).
This is a correct persistent storage API.
B. indexedDB
A low-level, client-side NoSQL database in the browser.
Stores large amounts of structured data and persists across reloads and sessions.
This is also a correct persistent API.
C. cookies
Small key/value pairs stored by the browser and often sent with HTTP requests.
Can have expiration dates and persist across page loads and sessions.
They are a traditional persistence mechanism in browsers.
So cookies also qualify.
D. global variables
Global JS variables exist only for the life of the current page context.
When the page is refreshed or navigated away, they are lost.
They do not persist between page loads.
E. IIFEs (Immediately Invoked Function Expressions)
A pattern for creating a new scope, not a persistence mechanism.
Variables inside an IIFE are still lost when the page reloads.
Thus, the three persistent browser APIs are:
localStorage
indexedDB
cookies
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit