Description of the difference between synchronous and asynchronous

There are two ideas in programming js: synchronous and asynchronous. Some people will tell do not know what is synchronous and asynchronous
want to distinguish that we first have to know the characteristics of single-threaded js. The so-called single-threaded is not completed until this thing is not going to do the next thing
that synchronization is good to understand. The matter has not been completed, continue to cook things, and so the matter will be completed next thing to do, most of the programming js are synchronized.
Asynchronous completely different, each task has one or more callback function (callback), after the execution of a task is completed, the next task is not executed immediately, but the callback function after a task is waiting for a front end of the mission on the implementation, so the order in the task execution order of the program is inconsistent, asynchronous, asynchronous can improve the efficiency.
Here I have to say asynchronous operation mechanism under
(1) all synchronization tasks are executed on the main thread to form a stack execution (execution context stack).
Addition (2) the main thread, there is a "Task Queue" (task queue). With asynchronous tasks run as long as a result, an event is placed in the "task queue" at home.
(3) Once the "execution stack" all synchronization task is finished, the system will read the "task queue" to see what events there. Those corresponding asynchronous tasks, thus ending the wait state, into the execution stack, started.
(4) the main thread is repeated the third step above.

Guess you like

Origin blog.csdn.net/xiaoHelloWord/article/details/94592181