Pesudo Asynchronous JavaScript

JavaScript inherently has Single threaded Synchronous Execution i.e. javascript is running on a single thread, line by line, in the sequence in which code is written.

But then the big question is how can it handle all the Events like Clicks or Hover and many other like. Even bigger question how AJAX works in JavaScript?

JavaScript is executing single Threaded Synchronously but the browser in which JavaScirpt is executing is not single Threaded as many other modules are also running. So, Whenever there is Event triggered our browser puts that event in event Queue and When javaScript is done with executing its code and is free It stars processing the events from event Queue one by one.

Its important to note JavaScript only handles Events when it is free i.e. not executing any code which you might have observerd a lot of times that web page is not responsing to your inputs or clicks.

This happens due to very fact that JavaScript handles events only when is not executing any of its sequential code and JavaScript is simple synchronous language using a power suit to show that its asynchronus.







Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s