0Pricing
JavaScript Academy · Lesson

The Call Stack

See how function calls are tracked.

What Is the Call Stack?

The call stack is how JavaScript tracks which function is currently running and what to return to. Every function call is pushed on top; when it finishes, it is popped off.

It is a LIFO structure: Last In, First Out.

Pushing and Popping

When you call a function, a stack frame is pushed. When it returns, the frame is popped. Watch the order of logs as calls nest.

function first() {
  console.log('first start');
  second();
  console.log('first end');
}

function second() {
  console.log('second');
}

first();

All lessons in this course

  1. The Call Stack
  2. Macrotasks and the Task Queue
  3. Microtasks and Promises
  4. queueMicrotask and Ordering
← Back to JavaScript Academy