Summary of Vue front-end interview questions (fourteen) async/await detailed explanation

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())

Insert picture description here

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

Guess you like

Origin blog.csdn.net/Rick_and_mode/article/details/108621123