Computer science fundamentals · Lesson 41 of 60 · Concept lesson · Optional
Memory management
The stack holds small, short-lived data such as a function's local variables, and the heap holds larger data that can live longer.
A reference is a value that points to data on the heap, so two names can point to the same data.
Garbage collection frees heap data that nothing refers to any more.
Picture it
Code example
const a = [1];
const b = a;
b.push(2);
console.log(a.length);Output: 2
b is not a copy. It points to the same array, so pushing through b also changes a.
a = [1]
b = a
b.append(2)
print(len(a))Output: 2
b is not a copy. It points to the same list, so appending through b also changes a.
Check yourself
Pick an answer for each question. You can retry as many times as you like.
Loading the questions…