Problem Statement
What is the main difference between localStorage and sessionStorage?
Explanation
Both localStorage and sessionStorage allow storing key-value pairs in the browser. The difference is lifespan — localStorage persists until manually cleared, while sessionStorage is cleared when the browser tab is closed. Both are synchronous and store only string data.
Code Solution
SolutionRead Only
<!-- sessionStorage Example -->
<script>
sessionStorage.setItem('theme', 'dark');
console.log(sessionStorage.getItem('theme'));
</script>