Interview Question

Difference between cookies and local storage?

Cookies can travel to the server; localStorage stays in the browser.

💡 Concept ✅ Quick Revision 🌐 HTML

Answer

Cookies and localStorage both save browser data, but they behave differently. • Cookies are small and may be sent with web requests. • localStorage stays in the browser and holds more data. • Choose the option whose defined semantics and behavior match the task.

💡 Simple Example

<p>Use a secure cookie for a login session and localStorage for a theme choice.</p>

⚡ Quick Revision

Cookies can travel to the server; localStorage stays in the browser.