Please share your thoughts on this. Someone might learn from your submission.
For further actions, you may consider blocking this person and/or reporting abuse
Please share your thoughts on this. Someone might learn from your submission.
For further actions, you may consider blocking this person and/or reporting abuse
ramadhan.dev -
Harutyun Mardirossian -
James -
M Sea Bass -
Top comments (6)
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 :)
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:
This is going to throw an error since
x
is not defined when we are trying to log it.Check this image out:
This will help you understand how JavaScript works.
And for more information check this article out:
How JavaScript Timers Work
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.
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.
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.
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.