Should I add a semicolon after a JavaScript statement?

Source: Internet
Author: User

It is entirely up to your personal habits to add and not add semicolons, but it is recommended to use semicolons for code stability (parsing errors).

JavaScript auto-semicolon rule:
1. When there are newline characters (including multiline comments with line breaks), and the next token cannot match the previous syntax, the semicolon is automatically complement.
2. When there is a semicolon is missing, a semicolon is complement.
3. When the program source code ends, if a semicolon is missing, the semicolon will be complement.
Conclusion:
1. In return, break, continue, post-increment, and post-decrement five statements, line breaks can completely replace the role of semicolons.
The 2.var if do and for continue break return with switch throw try debugger statements beginning with several keywords, as well as empty statements, with no effect on the previous line plus no semicolons.
3. In the case of expression statements and function expression statements, it is very dangerous to follow the semicolon without semicolons, which is extremely complex.
4. where (and [at the beginning of the statement, the front without semicolons is extremely dangerous.

Should I add a semicolon after a JavaScript statement?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.