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 )!