What are Cookies? — JS Technical Interview Questions & Answers
Small key-value pairs stored by the browser per domain.
What are Cookies?
- What are Cookies (js intro) is a JS topic. In plain words you use it for let total = 0 in a cart script. Don’t start with a slogan — start with that picture.
- Smallest example: let for change, const for fixed. Type it, run it, and say what you see. If you can do that from memory, you know What are Cookies (js intro).
- From the example next to this theory: Small key-value pairs stored by the browser per domain.
- Trap: var leak / const reassign. Fix that before you talk about advanced JS.
- Viva: what is What are Cookies (js intro)? Then show let for change, const for fixed. Then name the trap.
Technical Interview Tip: What is What are Cookies (js intro)? Show this: let for change, const for fixed. Trap: var leak / const reassign.
Code Examples for What are Cookies?
What are Cookies? — working example
// Browser:
// document.cookie = "theme=dark; Max-Age=86400; Path=/; SameSite=Lax";
// localStorage.setItem("theme", "dark");
// sessionStorage.setItem("draft", "hello");
// Runnable stand-in:
const jar = { theme: "dark" };
const store = new Map([["theme", "dark"]]);
console.log(jar.theme, store.get("theme"));
store.delete("theme");
console.log(store.has("theme"));What are Cookies? — cookies go to the server; localStorage persists; sessionStorage lasts for the tab.
How to Explain What are Cookies? to an Interviewer
What is What are Cookies (js intro)?
Used for let total = 0 a cart script Not just the heading
Give one small example of What are Cookies (js intro).
let for change, const for fixed Small key-value pairs stored by the browser per domain
What mistake do beginners make with What are Cookies (js intro)?
var leak / const reassign Show the fix
Where do you use What are Cookies (js intro)?
a cart script let total = 0