async/await
async and await are a synchronous way of writing but still asynchronous operations
async
The usage of async, put before the function as a keyword, means that the function is an asynchronous function, because async means asynchronous, and asynchronous function means that the execution of the function will not block the execution of the following code. The async function returns A promise object
async function A(){
return 'hello'
}
console.log(A())
await
- The meaning of await is to wait. It means that the code needs to wait for the function behind await to finish running and have a return result before continuing to execute the following code, the effect of synchronization
- When await is used as the evaluation keyword, it can be followed by Promise or expression, and the value in Promise or the value of expression and Promise can be directly obtained