In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the meaning of javascript asynchronism, which is very detailed and has certain reference value. Friends who are interested must finish reading it.
In JavaScript, asynchrony means that it is not executed according to the code order, the execution of an asynchronous process will no longer have a sequential relationship with the original sequence, and the execution order of the program is inconsistent with the order of tasks, which can be understood as asynchronism means sending a child thread from the main thread to complete the task.
The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.
What does javascript async mean?
The concept of Asynchronous
Asynchronous (async) is a concept relative to synchronization (Synchronous, sync).
In the traditional single-threaded programming we learned, the program runs synchronously (synchronization does not mean that all steps run at the same time, but that the steps are executed sequentially in a sequence of control flows). On the other hand, the concept of asynchrony is one that does not guarantee synchronization, that is, the execution of an asynchronous process will no longer be sequentially related to the original sequence.
To put it simply: synchronization is executed in your code order, asynchrony is not executed in code order, and asynchronous execution is more efficient.
The above is an explanation of the concept of asynchrony, and then let's explain it in a popular way: asynchrony is the emission of a child thread from the main thread to complete the task.
When to use asynchronous programming
In front-end programming (and sometimes even the back end), when we deal with short, fast operations, such as calculating the result of 1 + 1, it is often done in the main thread. As a thread, the main thread cannot accept multiple requests at the same time. Therefore, when an event does not end, the interface will not be able to handle other requests.
Now there is a button, and if we set its onclick event to an endless loop, then when this button is pressed, the entire page will become unresponsive.
To avoid this, we often use subthreads to accomplish things that may take long enough to be noticed by the user, such as reading a large file or making a network request. Because the child thread is independent of the main thread, even if blocking occurs, it will not affect the operation of the main thread. But the child thread has a limitation: once launched, it will be out of sync with the main thread, and we cannot be sure of its end. If we need to deal with something after it is finished, such as processing information from the server, we cannot merge it into the main thread.
In order to solve this problem, asynchronous operation functions in JavaScript often use callback functions to process the results of asynchronous tasks.
Asynchronous request and asynchronous loading of JS
Asynchronous request: the mode of communication in which the sender sends data and then sends the next packet without waiting for the receiver to send back a response.
Example: when the user fills in a piece of information, the information is automatically submitted to the server, and then the server responds to the client. In this process, the user is still filling out the information in the form, that is, requesting the server many times, saving the user's time and improving the user's experience.
Asynchronous loading: the default js is loaded synchronously ("load" here can be understood as parsing and executing). Asynchronous JS means to continue to execute the following js while the JS code is loaded.
For example: like this code.
Console.log ('hello world')
Our requirement seems to be very simple, to be able to output a string in the console while the page is loaded, to put it more colloquially, to continue to execute the following js, that is, to achieve asynchronous loading of js, while requesting the first paragraph of js provided by Google.
The above is all the content of this article "what does javascript asynchronism mean?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.