Does a semi-colon matter in JavaScript [duplicate]

2019-01-29 10:36发布

3条回答
Deceive 欺骗
2楼-- · 2019-01-29 10:38

If you don't put a semicolon at the end of the line, one will be added for you when your code runs.
However, it's very recommended to put the semicolons yourself, otherwise your code might not behave the way you expect it to.
For more info about this, i recommend you look up "Javascript - the good parts"
consider this example of why it's problematic.

查看更多
乱世女痞
3楼-- · 2019-01-29 10:49

Semicolons help in readability, especially if you use lots of whitespace and indents to make your code neater.

查看更多
走好不送
4楼-- · 2019-01-29 10:57

Semicolons act as a terminator of an expression or statement. It informs the script interpreter that the current expression or statement is done and to start with the next.

查看更多
登录 后发表回答