What is the Operator Precedence of Await?

后端 未结 1 351
长发绾君心
长发绾君心 2020-12-15 18:04

In Javascript certain operators are processed before others:

1 + 2 * 3
// 1 + (2 * 3)
// 7 because * has higher precedence than +

1 === 0 + 1
// 1 === (0 +          


        
相关标签:
1条回答
  • 2020-12-15 18:26

    An AwaitExpression is an UnaryExpression and has the same precedence as delete, void, typeof, +, -, ~, and !, binding stronger than any binary operator.

    This is unlike yield which has a precedence lower than anything else except the comma operator. This design decision was made because both yield a+b and await a + await b are scenarios thought to be more common than (yield a) + (yield b) and await (a + b).

    0 讨论(0)
提交回复
热议问题