DEV Community

Discussion on: Is JavaScript Synchronous or Asynchronous?

Collapse
adnanbabakan profile image
Adnan Babakan (he/him) • Edited on

Let's not confuse a language's itself with its features!
JavaScript is synchronous itself but features ways of dealing with functions we don't know when they are going to be called.
JavaScript has always been synchronous and single-threaded! When you are running a JavaScript block of code on a page no other block will be executed on that page at the same time.
JavaScript is synchronous when it comes to execution. Look at the code below:

console.log(x)

let x = 5

This is going to throw an error since x is not defined when we are trying to log it.

Check this image out:
JavaScript timer

This will help you understand how JavaScript works.

And for more information check this article out:
How JavaScript Timers Work

Collapse
mburszley profile image
Maximilian Burszley

Please don't conflate JavaScript with its engines. That is how the event loop works in a browser. It may not necessarily be the same as NodeJS for example.

Collapse
adnanbabakan profile image
Adnan Babakan (he/him)

I believe Nodejs is no different than the JavaScript that is run in the browsers. Nodejs is running under V8 engine and that acts pretty similar to browser JavaScript. It is single threaded and also synchronous.