JavaScript · Junior · Question 44 of 75
How does localStorage differ from sessionStorage?
- ✓Correct answer:
localStoragepersists indefinitely,sessionStorageuntil the tab is closed - 2
sessionStoragepersists indefinitely, whilelocalStoragelasts until the tab is closed - 3
localStorageis sent to the server with every request, whilesessionStorageisn't
Explanation
Both store strings per origin, a few megabytes in size, and aren't sent to the server (unlike cookies). sessionStorage is also isolated per tab. Storing tokens and secrets there is unsafe: any script on the page can read them.