DEV Community

loading...

How javascript works?

sourabhmahato profile image Sourabh Mahato ・1 min read

The Core Fact: "Everything in javascript happens inside an Execution Context"

Now, what's execution context?
You can assume it be a container where your whole code is executed.
Execution context has two components in it:

  1. Memory Component (Variable Environment)
  2. Code Component (Thread of Execution)

Now let's understand the role of each component in the execution context.

The first component, the memory component which is also known as the variable environment is responsible for storing all the variables and functions as key value pair. Long story short, it's sort of an environment which is used to store all the variables and functions as key : value pair.

The second component, the code component which is also known as the thread of execution is responsible for executing the code one line at once. It's called the thread of execution because it's like a thread in which the whole code is executed one line at a time.

Another core fact: "Javascript is a synchronous single-threaded language"

Let's understand why it's called single threaded because javascript can execute one command at a time. It's called synchronous single-threaded because javascript can execute one command at a time in a specific order. It means it can go to the next line only when the current line is being finished executing.

Conclusion: Javascript isn't possible without this execution context. It is a synchronous single threaded language.

Discussion (0)

pic
Editor guide