[JavaScript tutorial] JavaScript Annotation

Source: Internet
Author: User
JavaScript annotations can be used to improve code readability.

JavaScript comments

JavaScript annotations can be used to improve code readability.

JavaScript comments

JavaScript does not execute comments.

We can add comments to explain JavaScript or improve the readability of the Code.

A single line comment starts.

This example uses a single line comment to explain the Code:

Instance

// Output title: document. getElementById ("myH1 "). innerHTML = "Welcome to my homepage"; // output section: document. getElementById ("myP "). innerHTML = "this is my first paragraph. ";

JavaScript multi-line comment

Multi-line comments start with/* and end.

The following example uses multi-line annotations to explain the Code:

Instance

/* The following code will output a title and a paragraph and will represent the beginning of the home page */document. getElementById ("myH1 "). innerHTML = "Welcome to my homepage"; document. getElementById ("myP "). innerHTML = "this is my first paragraph. ";

Use annotations to prevent execution

In the following example, annotations are used to prevent execution of one of the code lines (which can be used for debugging ):

Instance

// Document. getElementById ("myH1"). innerHTML = "Welcome to my homepage"; document. getElementById ("myP"). innerHTML = "this is my first paragraph. ";

In the following example, annotations are used to prevent code block execution (which can be used for debugging ):

Instance

/* Document. getElementById ("myH1"). innerHTML = "Welcome to my homepage"; document. getElementById ("myP"). innerHTML = "this is my first paragraph. ";*/

Comment at the end of the row

In the following example, we place the comment at the end of the code line:

Instance

Var x = 5; // declare x and assign 5 to var y = x + 2; // declare y and assign x + 2 to it

The above is the content of the JavaScript annotation in the [JavaScript tutorial]. For more information, see the PHP Chinese website (www.php1.cn )!

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.