EverythingToKnow
1 min readApr 23, 2024

Is Javascript a Multi-threaded or Single-threaded Language?

JavaScript is often described as a single-threaded language, but what does that mean exactly? And how does it impact the way we write code? Let’s see.

In JavaScript, there is only one thread of execution, meaning that code is executed sequentially from top to bottom.From the below example,

console.log(“Hello”);

setTimeout(() => {
console.log(“World”);
}, 1000);

console.log(“JavaScript”);

we have a console.log statement printing "Hello", followed by a setTimeout function that schedules the printing of "World" after a delay of 1000 milliseconds. Finally, we have another console.log statement printing "JavaScript". Despite the delay in the setTimeout function, the code will execute sequentially, So what do you think the output would be?

Hello
JavaScript
World

Confused right? Since Javascript is a single-threaded language,that means it executes code line by line in a sequential order but that does not means that it would wait for 1 operation to be completed as “Javascript waits for no one”

Even though “World” is scheduled to be printed after 1000 milliseconds, it doesn’t block the execution of subsequent code.This showcases the single-threaded nature of JavaScript.

Want to know more Concepts like this??..then hit the follow Button!!

EverythingToKnow

🚀 Welcome to EverythingToKnow! 🚀Discover the world of programming languages through our comprehensive blog!