DEV Community

Ranjit budhathoki
Ranjit budhathoki

Posted on

JavaScript is single threaded programming language. What does it mean?

Single threaded programming language simply means that the language can execute only one task at a time.

Let us say there are three functions in our code.

function add (a,b){
   console.log(a+b);
}

function subtract (a,b){
   console.log(a-b);
}


function multiply(a,b){
   console.log(a*b);
}

Enter fullscreen mode Exit fullscreen mode

when all these functions are called like below

add(1,2);
subtract(3,2);
multiply(4,1);
Enter fullscreen mode Exit fullscreen mode

These functions runs on a sequence, first the add function gets executed, then subtract function gets executed and then finally multiply function gets executed.

The add function runs before subtract function and it blocks the execution of subtract function until the execution of add function is completed.

Top comments (3)

Collapse
 
sarveshprajapati profile image
Sarvesh Prajapati

You are discussing a code concept of JS, so why not express it like the way it deserve.
There are several topics you should discus...

  • Call Stack
  • Event queue

Either way, great content

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
sarveshprajapati profile image
Sarvesh Prajapati

Just keep writing :)