let myVar = "" let asyncAccessURL = async function () { myVar = "landmark1" const f1 = await fetch('https://www.baidu.com'); myVar = "landmark2" const f2 = await fetch('https://www.baidu.com'); myVar = "landmark3" console.log(f1); console.log(f2); }; asyncAccessURL().then(console.log(myVar))
then接收的是一个回调函数作为参数,then(res=>{})//是个未执行的函数。你这么写then(console.log())//相当于把console.log()的返回结果(undefined)传给了then;而console.log(myVar)在第一时间执行并输出在控制台了。
asyncAccessURL().then(undefined);
2.1m questions
2.1m answers
60 comments
57.0k users