Suggest an editImprove this articleRefine the answer for “What is the call stack (call stack)?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)The **call stack** is a data structure that the JavaScript engine uses to track the execution of functions in a program. **Key point:** the stack works on the **LIFO** principle (Last In - First Out).Shown above the full answer for quick recall.Answer (EN)ImageThe **call stack** is a data structure that the JavaScript engine uses to track the execution of functions in a program. ### How it works While executing code, JavaScript needs to know: - **which function is running right now**, - **where it was called from**, - **where to return after it finishes**. For this it uses the **call stack** - a structure that works on the **LIFO** principle (Last In - First Out). ### What this looks like in practice Example: ```javascript function a() { console.log('a'); b(); } function b() { console.log('b'); c(); } function c() { console.log('c'); } a(); ``` #### Step by step: 1. `a()` is called -> pushed onto the stack. **Stack:** `[a]` 2. `a()` calls `b()` -> `b()` is added. **Stack:** `[a, b]` 3. `b()` calls `c()` -> `c()` is added. **Stack:** `[a, b, c]` 4. `c()` finishes -> it is removed. **Stack:** `[a, b]` 5. `b()` finishes -> it is removed. **Stack:** `[a]` 6. `a()` finishes -> it is removed. **Stack:** `[]` (empty) ### What happens with infinite recursion If a function calls itself with no exit: ```javascript function recurse() { recurse(); } recurse(); ``` Every call is added to the stack, but is never removed. In the end, a **"Stack overflow"** error occurs, meaning the call stack has overflowed. ### Relation to the Event Loop JavaScript is **single-threaded**, meaning that at any given moment only **one function from the stack** is executing. When the stack is empty, the engine can take the next task from the **callback queue** and start a new Event Loop cycle. ### Summary | Term | Description | | --- | --- | | **Call Stack** | Where the engine stores the execution context of functions | | **LIFO** | Last called - first finished | | **Stack Overflow** | Error when the stack overflows | | **Relation to Event Loop** | When the stack is empty, callbacks and promises are processed |For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.