DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,503 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Edison Ade
Edison Ade

Posted on

Is JavaScript Synchronous or Asynchronous?

Please share your thoughts on this. Someone might learn from your submission.

Top comments (6)

Collapse
 
shahrozahmd profile image
Shahroz Ahmed

javascript is synchronous by nature but it has a lot of features like callbacks, promises, async/await which allows you to implement asynchronous event handling in your project... hope you get the point :)

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.

Collapse
 
calix profile image
Calix Huang

Javascript can be either asynchronous or synchronous. Javascript is most known for being asynchronous because it can be, while other programming languages are multi-threaded at best. It is a huge advantage over other languages because it's so much faster.

Collapse
 
mburszley profile image
Maximilian Burszley • Edited on

You're confusing a lot of concepts here. Concurrency (async) has nothing to do with threading vs multiprocessing or whatever model you use. It's about "parallel" execution. JavaScript is synchronous by default. JavaScript is just a language, it is neither fast or slow. That is up to its engines.

Update Your DEV Experience Level:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›