Skip to main content

What is asynchronous programming, and why is it important in JavaScript?

Synchronous programming means that, barring conditionals and function calls, code is executed sequentially from top-to-bottom, blocking on long-running tasks such as network requests and disk I/O.
Asynchronous programming means that the engine runs in an event loop. When a blocking operation is needed, the request is started, and the code keeps running without blocking for the result. When the response is ready, an interrupt is fired, which causes an event handler to be run, where the control flow continues. In this way, a single program thread can handle many concurrent operations.
User interfaces are asynchronous by nature, and spend most of their time waiting for user input to interrupt the event loop and trigger event handlers.
Node is asynchronous by default, meaning that the server works in much the same way, waiting in a loop for a network request, and accepting more incoming requests while the first one is being handled.
This is important in JavaScript, because it is a very natural fit for user interface code, and very beneficial to performance on the server.

Comments

Popular posts from this blog

Learn HTML in Hindi - 1st lesson.

अधिकांश HTML तत्वों में एक प्रारंभिक टैग और एक समापन टैग होता है। उद्घाटन टैग इस तरह दिखते हैं: <H1> बंद टैग इस तरह दिखते हैं: </ H1> उद्घाटन और समापन टैग के बीच एकमात्र अंतर एक समापन टैग के उद्घाटन ब्रैकेट के बाद आगे की स्लैश है।  

Learn JavaScript - Introduction

JavaScript program is made up with series of statements and each statement ends with a new line or semicolon. Its not compulsory to terminate a statement with semicolon as JavaScript interpreter use a process called Automatic Semicolon Insertion(ASI). This process will attempt to place semicolons at the end of the line for you. But, it is best practice to write statement in a new line and terminate by a semi-colon. # JavaScript # beginner # tutorial