I want to test use loop to await
.
// works fine
async function asyncFunc() {
let arr = ['a', 'b', 'c'];
for (let i = 0; i < arr.length; i++) {
console.log(await arr[i]);
}
}
asyncFunc()
async function asyncFunc() {
let arr = ['a', 'b', 'c'];
arr.forEach(function(el) { // get an error: SyntaxError: missing ) after argument list
console.log(await el);
})
}
asyncFunc()
async function asyncFunc() {
let arr = ['a', 'b', 'c'];
arr.forEach((el) => { // get an error here: SyntaxError: missing ) after argument list
console.log(await el);
})
}
asyncFunc()
Can someone tell me what's wrong here?
editor: VS code
node: 8.0.0
I know that i can't use await
out of the current async function
context.
So i am sure i will get an error on the second one.
But i do not know why i also get an error on the third one. Does the arrow function and the async function have the different context ???