On the use of the semicolon in JavaScript _javascript skills

Source: Internet
Author: User

Is it necessary to add a semicolon to the beginning of a function in JS? Should I add a semicolon after the JS statement? Should a semicolon be used after JavaScript braces? JS function in the beginning of the exclamation point, semicolon what does it mean?

JS multiple files integrated into a file, compressed code to avoid syntax errors, you can deal with the following

One, JS Front plus semicolon

For example:;(function ($) {... Here's the code ...}) ();
In JavaScript, a semicolon denotes the end of a statement, which, at the beginning, is separated from other methods for compression, indicating that a new statement begins

Second, JS function plus semicolon

For example

Module 1
//preceded by a number
of code var Manager = {
 prop: ',
 method:function () {

 }
}
//Module 2, beginning with an immediate execution function
(function () {
 //Code
}) ()

After compression becomes:} (function there, it will be executed as a functions, so the whole parsing will be wrong

Copy Code code as follows:

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

Workaround: Add a semicolon after the manager function

The above mentioned is the entire content of this article, I hope you can enjoy.

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.