mirror of
https://github.com/KieSun/all-of-frontend.git
synced 2024-11-23 15:28:14 +08:00
feat: 17 答案
This commit is contained in:
parent
c8800f31eb
commit
c4eeb40434
14
Answer/11-20/17.md
Normal file
14
Answer/11-20/17.md
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
```js
|
||||||
|
var a = 0
|
||||||
|
var b = async () => {
|
||||||
|
a = a + await 10
|
||||||
|
console.log('2', a) // -> ?
|
||||||
|
}
|
||||||
|
b()
|
||||||
|
a++
|
||||||
|
console.log('1', a) // -> ?
|
||||||
|
```
|
||||||
|
|
||||||
|
这道题目大部分读者肯定会想到 `await` 左边是异步代码,因此会先把同步代码执行完,此时 `a` 已经变成 1,所以答案应该是 11。
|
||||||
|
|
||||||
|
其实 `a` 为 0 是因为加法运算法,先算左边再算右边,所以会把 0 固定下来。如果我们把题目改成 `await 10 + a` 的话,答案就是 11 了。
|
Loading…
Reference in New Issue
Block a user