Ajax-synchronous and asynchronous concept

Synchronous and asynchronous concept
synchronization: one person can only do one thing at a time, and only one thing can be done before another.
Implemented into the code, that is, after the execution of the previous line of code is completed, the next line of code can be executed, that is, the code is executed line by line.

Asynchronous: A person does half of a thing and turns to do other things. When other things are done, they go back and continue to do the things that were not completed before they are
implemented into the code. That is, asynchronous code takes time to execute , But the program will not wait for the completion of the execution of the asynchronous code before continuing to execute the follow-up code,
but directly execute the follow-up code. When the follow-up code is completed, look back to see if the asynchronous code returns the result. If there is a return result,
call the preparation in advance Good callback functions handle asynchronous code execution results.
console.log ('before');
setTimeout (() => {
console.log ('last');
}, 2000);
console.log ('after');

Guess you like

Origin www.cnblogs.com/technicist/p/12742483.html