Category: javascript
Local Storage
Published on 16 Jul 2026
Explanation
Local Storage stores data permanently in the browser.
Code:
localStorage.setItem('name','John');
Explanation
Stored values can be retrieved using getItem().
Code:
console.log(localStorage.getItem('name'));
Explanation
Session Storage stores data only for the current browser tab.
Code:
sessionStorage.setItem('token','123');
Explanation
Stored data can be removed using removeItem().
Code:
localStorage.removeItem('name');
Explanation
clear() removes all stored values.
Code:
localStorage.clear();