As you can see, the
localStorage syntax is very straightforward and makes storage and retrieval easy. So why hasn’t everything transitioned to using
sessionStorage? What are the pros and cons of each? Below, we’ll compare cookies and
Though both cookies and browser storage are a form of client-side storage, they differ in a number of ways.
localStorage is also newer, so there is less browser compatibility. The syntax to access this storage is also arguably simpler.
There is also the difference in data expiry and capacity. Cookie expiration can be configurated through code, but
sessionStorage expiration work differently and are more so dependent on browser operations. Cookies hold 4KB per domain, whereas
sessionStorage have greater capacity per domain.
Take a look at the side-by-side comparison!