Skip to content

Commit

Permalink
feat: 17 答案
Browse files Browse the repository at this point in the history
  • Loading branch information
KieSun committed Mar 30, 2021
1 parent c8800f3 commit c4eeb40
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Answer/11-20/17.md
Original file line number Diff line number Diff line change
@@ -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 了。

0 comments on commit c4eeb40

Please sign in to comment.