Home > Article > Web Front-end > A brief discussion on the use of semicolons in javascript_javascript skills
Is it necessary to add a semicolon at the beginning of function in JS? Should I add a semicolon after the js statement? Should semicolons be used after JavaScript braces? What does the exclamation mark and semicolon at the beginning of function in JS mean?
After integrating multiple JS files into one file, to avoid syntax errors when compressing the code, you can handle it as follows
1. Add a semicolon before js
For example:;(function($){...code here...})();
In Javascript, a semicolon indicates the end of a statement. It is added at the beginning to separate it from other methods during compression and indicates the beginning of a new statement
2. Add a semicolon after the js function
For example
// 模块1 // 前面有若干代码 var Manager = { prop: '', method: function () { } } // 模块2,开头是个立即执行函数 (function () { // 代码 })()
After compression, it becomes: }}(function where it will be executed as a function, so the overall analysis will be wrong
Solution: Add a semicolon after the Manager function
The above is the entire content of this article, I hope you all like it.