- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript sessionStorage
JavaScript Storage & BOM
JavaScript sessionStorage
sessionStoragebehaves likelocalStoragebut clears when the tab closes.
The methods are identical; only the lifetime differs.
Each tab also gets its own separate storage.
Example
Example
javascript
sessionStorage.setItem("step", "2");
console.log(sessionStorage.getItem("step"));The output is 2.
How It Differs
Data is cleared when the tab or window closes.
Each tab has its own storage, even for the same site.
