Memory Ram architecture

Fixed Size data: Stack, dynamic size: Heap

4 bit architecture

Garbage Collector

Chart table

Unit Symbol Conversion In Bytes
Byte B Base unit 1 B
Kilobyte KB 1 KB = 1024 B 2¹⁰ B
Megabyte MB 1 MB = 1024 KB 2²⁰ B = 1,048,576 B
Gigabyte GB 1 GB = 1024 MB 2³⁰ B = 1,073,741,824 B
Terabyte TB 1 TB = 1024 GB 2⁴⁰ B ≈ 1.1 trillion B
Petabyte PB 1 PB = 1024 TB 2⁵⁰ B ≈ 1.13 quadrillion B
Exabyte EB 1 EB = 1024 PB 2⁶⁰ B ≈ 1.15 quintillion B
Zettabyte ZB 1 ZB = 1024 EB 2⁷⁰ B ≈ 1.18 sextillion B
Yottabyte YB 1 YB = 1024 ZB 2⁸⁰ B ≈ 1.21 septillion B

Where the Data is actually stored?

The Two Memory Regions in V8

When your JavaScript code runs, the V8 engine manages two primary areas of memory:

  1. The Call Stack: A highly organized region for managing function execution. It's fast and stores fixed-size data. On a 32-bit system, the "slots" on the stack are 32 bits (4 bytes) each.
  2. The Heap: A large, less organized region for storing data that can change in size or has a longer lifetime. This is where objects, arrays, and other complex data live.

How Primitive Data is Stored (The V8 Reality)

This is where V8's optimizations are critical. It does not follow a simple "all primitives on the stack" rule.

number (The Hybrid Approach)

V8 splits numbers into two types to maximize performance:

  1. Smi (Small Integer): code JavaScript

        let loopCounter = 100; // This is a Smi. Its value lives on the stack.
    
  2. HeapNumber: code JavaScript

        let price = 19.99; // This is a HeapNumber. 'price' on the stack is a pointer to an object on the heap.