当前位置:网站首页>await is only valid in async function
await is only valid in async function
2022-06-23 01:54:00 【web15085547941】
This mistake means await It can only be put in async Internal function , The implication :
- await Must be put in the function
- Function must have async Modifier
error 1: Not in the function
const myFun = async () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(1)
},1000)
})
}
// error : Not in the function
res1 = await myFun();
console.log(res1);
// SyntaxError: await is only valid in async function
error 2: Function does not async Modifier
const myFun = async () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(1)
},1000)
})
}
// error : Function does not async Modifier
const myFun2 = () => {
res1 = await myFun();
console.log(res1);
}
myFun2();
// SyntaxError: await is only valid in async function
Write it correctly
const myFun = async () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(1)
},1000)
})
}
const myFun2 = async () => {
res1 = await myFun();
console.log(res1);
}
myFun2();
// 1
边栏推荐
- Data analysis method - user group analysis
- //1.7 use of escape characters
- Bubble sort - double for implementation
- JS to paste pictures into web pages
- 7.new, delete, OOP, this pointer
- Exercise analysis summary
- Ch340 and PL2303 installation (with link)
- Pat class A - 1007 maximum subsequence sum
- Cmake passing related macros to source code
- Autumn move script B
猜你喜欢

II Data preprocessing

Foundation Consolidation - Flex width is content width

Express framework installation and start service

Lexical Sign Sequence

Zabbix5 series - use temperature and humidity sensor to monitor the temperature and humidity of the machine room (XX)

4. functions and inline functions with default values for formal parameters

JS prototype and prototype chain Paramecium can understand

How to type Redux actions and Redux reducers in TypeScript?

Function part

Cmake configuration error, error configuration process, Preject files may be invalid
随机推荐
[luogu] p1083 [noip2012 improvement group] borrow classroom (line segment tree)
Operator part
Zabbix5 series - use temperature and humidity sensor to monitor the temperature and humidity of the machine room (XX)
Game (sanziqi & minesweeping)
Targeted and ready to go
Classical questions of function recursion
Data analysis method - user group analysis
//1.9 char character variable operation
1. Mx6u image burning principle (no specific process)
[Luogu] P2887 Sunscreen G
Array part
Error C2061 syntax error: identifier ‘PreparedStatement‘
Centos7 installing postgresql12
You can be what you want to be
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
Char[], char *, conversion between strings
3. compilation and linking principle
//1.17 printf function
Cmake passing related macros to source code
C. Number of Pairs-Codeforces Round #725 (Div. 3)