Cookies versus local storage

By now, you may have observed that cookies and local storage serve almost completely different purposes. The only thing they have in common is that they store data. The following is a brief comparison of cookies and local storage:

Cookies Local storage
Cookies are transferred to a server on every request automatically by the browser To transfer local storage data to a server, you need to manually send an Ajax request or send it through hidden form fields
If data needs to be accessed and read both by the client and server, use cookies If the data needs to be accessed and read only by the client, use local storage
Cookies can have an expiration date, after which they are automatically deleted Local storage ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.