Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript What is Local Storage and Why Use It?

Owa Aquino
Owa Aquino
19,277 Points

is Local Storage = Web Cookies?

What's the difference between Local Storage and Web Cookies?

1 Answer

Hi Owa,

Local Storage and Cookies are very similar, but ultimately different, storage mechanisms. Actually, the only similarity between them is that they both store data on your client (your Browser). Cookies, though, can have that data read back on the server-side; Local Storage is not accessible from the server. Also, Cookies can have expiration dates whereas Local Storage data does not.

That's the extent of the comparison that I can generate off the top of my head right now. If you need more info on this topic, a simple Google search should turn up some helpful results.

Owa Aquino
Owa Aquino
19,277 Points

Hi Mikis,

I get it now. So when a site ask for the clients to turn on the Cookies does this mean they monitoring your actions on your browsers or in that specific site only?

So if you've turned off Cookies in your browser, it means that websites can't save any data to your browser. Websites can only access data from your browser that they saved or that you send them. For example, they can't access your history, or your bookmarks. The use-case for Cookies is usually something to do with social-media or the collection of analytics data. Around 5 years ago, the European Union passed some legislation that requires websites to gain consent before saving any type of data to a user's machine; this is why you see pop-ups asking you for permission regarding Cookies.

Also, I left something out above: just because your browser doesn't send the data in Local Storage back to the server — like what happens with Cookies — doesn't mean that a website can't use JavaScript embedded in the page to retrieve the Local Storage data and subsequently send that data to the server, using something like AJAX. Still — even with this workaround — sites can only access data that they themselves saved at some point.

Owa Aquino
Owa Aquino
19,277 Points

Mikis,

This is great I learned so much from you today. Thank you very much! :)

You're welcome ;)