...
/How JavaScript Works—Execution Context
How JavaScript Works—Execution Context
Learn how JavaScript code is executed internally using the execution context.
We'll cover the following...
Introduction
In this lesson, we will learn about how JavaScript works and how JavaScript code is executed behind the scenes. We will also answer two questions:
Is JavaScript a synchronous or an asynchronous language?
Is JavaScript a single-threaded or a multi-threaded programming language?
Execution context
Everything in JavaScript happens inside an execution context. You can think of this execution context as a big container in which the whole JavaScript code is executed. An execution context consists of two components: the variable environment and the thread of execution.
Below is a simple illustration to help you understand the design of the execution context.
Let's go over each of those components:
Variable environment: This first component (also known as the memory component) is an environment where all the variables and functions are stored as key-value pairs. For example, let's assume we have a variable
a
, whose value is set to10
. It will be held in the variable environment ...