Explain the difference between localStorage, sessionStorage, and cookies in HTML5.

Instruction: Describe the functionalities and differences of localStorage, sessionStorage, and cookies.

Context: The question tests the candidate's knowledge of client-side storage mechanisms provided by HTML5 and their ability to distinguish between them in terms of scope, lifecycle, and capacity.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

localStorage and sessionStorage are synchronous string key/value stores. They are not automatically attached to HTTP requests. Both use origin boundaries, subject to browser storage/privacy policy; sessionStorage additionally separates top-level browsing contexts.

localStorage can persist across sessions but has no guarantee against deletion, eviction or access denial. sessionStorage survives reloads during a page session and normally ends with that tab's session...

Related Questions