Single-threaded in JavaScript

Koushik SahaKoushik Saha
1 min read

Note: JavaScript is a single-threaded, non-blocking, asynchronous, concurrent a programming language with lots of flexibility.

JavaScript is a single-threaded language because while running code on a single thread, it can be really easy to implement as we don't have to deal with the complicated scenarios that arise in the multi-threaded environment like deadlock. Since, JavaScript is a single-threaded language, it is synchronous in nature.

In JavaScript we can consider Single-threaded as Call Stack.

What is Call Stack :

Within the call stack, your JS code is read and gets executed line by line.

JavaScript is a single-threaded language, which means it has only one call stack that is used to execute the program.

When ever JS run, In Call Stack global execution context created, even if script has no code global execution context will be created. and execute code one by one synchronously. When ever global execution context meet a function, in code part another execution context will be created for that function, and code will execute one by one.

function abc(){
console.log("Hello i am abc function");
}

function abcd(){
console.log("Hello i am abcd function");
}

abc();
abcd();

how js run.png

1
Subscribe to my newsletter

Read articles from Koushik Saha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Koushik Saha
Koushik Saha

A Good Learner. And Web Developer.