Home > Web Front-end > JS Tutorial > body text

A brief discussion on the use of semicolons in javascript_javascript skills

WBOY
Release: 2016-05-16 15:59:46
Original
1241 people have browsed it

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 () {
 // 代码
})()

Copy after login

After compression, it becomes: }}(function where it will be executed as a function, so the overall analysis will be wrong

Copy code The code is as follows:

var Manager = {prop: '',method: function (){}}(function () {})()

Solution: Add a semicolon after the Manager function

The above is the entire content of this article, I hope you all like it.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!