HTML5 - localStorage vs sessionStorage
In this article, we would like to show you the difference between localStorage and sessionStorage in HTML5.
Quick solution:
The difference between localStorage and sessionStorage is the data storage time. While data in localStorage doesn't expire (it can only be explicitly deleted), data in sessionStorage is cleared when the web browser session ends for the page (do not confuse it with server sessions).
1. Overview
The localStorage and sessionStorage both extend Storage that can store key/value (property/value) pairs and has built-in methods (like .length, .key( ), etc.).
2. localStorate
The localStorage stores data permanently. Once saved data is already there and the application can refer to it at any time, regardless of the session, unless the user manually deletes the contents of localStorage. There is also no built-in mechanism that would say how long data can be stored in localStorage (as e.g. in the case of cookies).
3. sessionStorate
The sessionStorage only works for the duration of the session. After the session ends, its storage is deleted.