The letters 'JS' within a square

JavaScript: V8 Engine

How the V8 engine works

The letters 'JS' within a square

JavaScript: V8 Engine

How the V8 engine works

V8 Engine

Source Code

Memory Heap

Call Stack

Console

V8 Engine

Source Code

Memory Heap

Call Stack

Console

JavaScript is a single-threaded scripting language. This means it can only do 1 thing at a time.

It has 1 call stack. An array with 2 operations: push (adds an element to the top) & pop (removes an element from the top). “Last In, First Out” protocol (LIFO).

When the engine executes a script, it pushes the global execution context, main(), into the call stack. Items in the call stack are called stack frames.

The engine executes code synchronously. Top to bottom, line by line.

When a function is invoked, its execution context gets pushed into the call stack.

When the function returns (or there are no more lines to execute), it gets popped out of the call stack.

The engine then executes the next line.

The script will stop when the call stack is empty.

/index.js

function func3() {
    console.log("3 invoked")
}

function func2() {
    console.log("2 invoked")
    func3()
}

function func1() {
    console.log("1 invoked")
}

func1()
func2()
                    
An arrow pointing right
2 arrows pointing left & right
main()
func1()
func2()
func3()
> 1 invoked > 2 invoked > 3 invoked >

Purpose: to compile JavaScript
Implements ECMAScript as specified in ECMA-262
Open source
Developed by Google
Written in C++

Runs inside a hosting environment:
- web browser
- a server (Node.js)

Used in Chromium based browsers:
- Google Chrome
- Microsoft Edge