JavaScript
  • JavaScript Introduction
  • JS Engine
  • V8 Engine
  • First-class function
  • Optimized Code
  • Call Stack & Memory heap
  • Single Thread
  • JavaScript RunTime
  • Nodejs
  • Context and Environment
  • Hoisting
  • Functions
  • Arguments
  • Variables
  • Scope
  • IIFE
  • this
  • call(), apply() and bind()
  • currying
  • Types
  • Type Coercion
  • Functions as Object
  • HOF (Higher Order Function)
  • Two pillars of Javascript
  • Closures
  • Prototypal Inheritance
  • OOP and FP
  • OOP
    • 4 principles of OOP
  • FP
    • Pure function
    • Imperative vs Declarative
    • Immutability
    • HOF and Closures
    • Currying
    • Partial Application
    • Compose and Pipe
  • Composition vs Inheritance
  • OOP vs FP
  • JS working
  • Promises
  • Async Await
  • ES5 - ECMAScript 2009
  • ES6 - ECMAScript 2015
  • ES7 - ECMAScript 2016
  • ES8 - ECMAScript 2017
  • ES9 - ECMAScript 2018
  • ES10 - ECMAScript 2019
  • ES11 - ECMAScript 2020
  • ES12 - ECMAScript 2021
  • JOB Queue
  • Promises Execution
Powered by GitBook
On this page
  • Call Stack:
  • Memory Heap:
  • Stack Overflow:
  • Garbage Collection:
  • Memory Leaks:

Was this helpful?

Call Stack & Memory heap

Call Stack:

  • Call Stack is the place where the code execution has been tracked.

  • Every data in the call stack will be pointed to the memory heap.

  • Follows Last In First Out (LIFO).

Memory Heap:

  • Memory heap is the place where the memory is allocated for the variables and functions etc.

Stack Overflow:

  • When the function runs inside and inside, the call stack will be filled and overflows.

  • When the stack overflows, Maximum call stack size exceeded error will be thrown.

  • The below function runs inside and inside and the stack will be overflowed.

Ex: 
function inception() {
    inception();
}
 inception();

Garbage Collection:

  • JavaScript automatically cleans out the memory allocated to the data after its execution. For example when the memory allocated for the variable created inside the function, it will be cleared after the function execution automatically.

  • It will manages the memory leaks.

  • It will automatically controls the memory heap.

  • It follows Mark and Sweep algorithm to handle Garbage collection.

Memory Leaks:

  • Memory leaks occurred when the data is overloaded (Infinite data into an array), it breaks the browser.

Ex:
let array = [];
for(let i=1; i>0; i++) {
    array.push(i);
}

PreviousOptimized CodeNextSingle Thread

Last updated 5 years ago

Was this helpful?