Why are semicolons not used after if/else statements?

前端 未结 3 899
悲哀的现实
悲哀的现实 2020-12-08 06:59

I understand that it is good syntax to use semicolons after all statements in Javascript, but does any one know why if/else statements do not require them after the curly br

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 07:46

    Because the curly braces themselves are termination characters.

    The are tokens that enclose a compound statement block and are intrinsically terminated. It's like putting a period at the end of a sentence, it signals to the parser that the thought is complete.

    While being completely ugly it is valid to wrap every statement in {} and omit the ;

提交回复
热议问题