In JavaScript, synchronization means that the next task is executed after the previous task is completed. The program execution order is consistent with the order of the tasks. A major feature of the JS language is that single thread, at the same time You can only do one thing, which means that you can't move on to the next thing until one thing is finished.
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
What does javascript synchronization mean?
One of the major features of S language is that it is single-threaded and can only do one thing at the same time. It means that after one thing is finished, the next thing can be done.
HTML5 proposes the Web Worker standard, allowing JavaScript scripts to create multiple threads. So there are synchronous and asynchronous.
Synchronization:
The next task is executed after the previous task is completed. The program execution sequence is consistent and synchronized with the task arrangement sequence.
Asynchronous:
Can handle other events while doing one thing.
同步和异步
When outputting the results, the first statement is displayed first, then the third statement, and the second statement is displayed after waiting for 5 seconds.
The difference between synchronous and asynchronous is that the execution order of each process on the pipeline is different
When the timer time is 0, what kind of printing order will it be? Change the timer time of the above program to 0, execute the program, and find that the output sequence has not changed.
JS divides all tasks into two categories, synchronous tasks and asynchronous tasks
Synchronous tasks are executed on the main thread, forming an execution stack; asynchronous tasks are implemented through callback functions of.
There are three types of common asynchronous tasks:
Ordinary events: such as click, resize, etc.
Resource loading, such as load, error, etc.
Timers, including setInterval, setTimeout, etc.
Execute the synchronous tasks in the execution stack first, and put the asynchronous tasks into the task queue. Once all the synchronous tasks in the execution stack are completed, the system will read the asynchronous tasks in the task queue in order, so The asynchronous task being read ends the waiting state and enters the execution stack.
Related recommendations:javascript learning tutorial
The above is the detailed content of What does javascript synchronization mean?. For more information, please follow other related articles on the PHP Chinese website!