Home  >  Article  >  Web Front-end  >  How does javascript express it at the end?

How does javascript express it at the end?

藏色散人
藏色散人Original
2021-07-02 15:06:511343browse

Javascript can be expressed with a semicolon at the end, but whether to add a semicolon or not depends entirely on personal habits. However, for the sake of code stability, it is still recommended to use semicolons to break sentences.

How does javascript express it at the end?

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

How to express JavaScript at the end?

The end of JavaScript statement can be expressed with semicolon;.

Whether to add semicolons or not depends entirely on personal habits, but for the sake of code stability (parsing errors), it is recommended to use semicolons to break sentences.

JavaScript automatic semicolon rules:

1. When there is a newline character (including multi-line comments containing newline characters), and the next token cannot follow the previous one When the syntax of "matches", semicolon will be automatically added.

2. When there is }, if there is a missing semicolon, the semicolon will be added.

3. When the program source code ends, if a semicolon is missing, it will be filled in.

Conclusion:

1. In the five statements of return, break, continue, post-increment, and post-decrement, the newline character can completely replace the role of the semicolon.

2.var if do while for continue break return with switch throw try debugger statements starting with several keywords, as well as empty statements, whether or not a semicolon is added to the previous line has little effect.

3. It is very dangerous not to add a semicolon after any expression statement or function expression statement, and the situation is extremely complicated.

4. Any statement starting with ( and [ without a semicolon in front is extremely dangerous.

Recommended study: "javascript Advanced Tutorial"

The above is the detailed content of How does javascript express it at the end?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn