Step 1 of 6
Two kinds of storage

JavaScript uses two areas of memory. The stack keeps track of function calls and their local variables. The heap stores objects. The garbage collector only cleans up the heap.

What to notice
The JavaScript spec never mentions a stack or a heap. They describe how engines like V8 work, and that's the model interviewers expect you to use.
The code
1
// A user opens a question on devtools.tech.
2
// number
3
let questionId = 402;
4
// boolean
5
let isPremium = true;
6
// string: its text lives on the heap
7
let slug = "debounce";
8
9
// stored on heap
10
let question = {
11
slug,
12
difficulty: "medium",
13
};
14
15
// stored on heap
16
let tags = ["react", "closures"];
17
18
function startTimer() {
19
// used by the inner function, so kept on the heap
20
let seconds = 0;
21
return () => ++seconds;
22
}
23
24
let onTick = startTimer();
Practice for your next interview
290+ interview questions, a frontend system design guide with case studies, premium roadmaps, AI code reviews, and much more.
Explore more →
Stack vs heap
Stack
Heap
questionId
402
isPremium
true
slug
ref
question
ref
tags
ref
"debounce"●STRING
Question●ALIVE
slug:"debounce"
difficulty:"medium"
Array(2)●ALIVE
0:"react"
1:"closures"
01 / 06
Space to advance · ← → to step