AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

JavaScript Comments


JavaScript Tutorial » JavaScript Comments

Comments are usually used with the purpose of providing extra information, to explain JS code, and to make it more readable and also can be used to prevent execution of alternative JS code.

JS support single line and multiline comments.


Single Line Comments - example


Single line comments start with // and text between // and the end of the line will be ignored by JS

Example:
<!DOCTYPE html>
<html>
<body>

<h1 id="my_title"></h1>
<p id="my_paragraph"></p>

<script>
// this is my comment line Change heading:
document.getElementById("my_title").innerHTML = "My Title - JavaScript Comments";
// This is another coment line Change paragraph:
document.getElementById("my_paragraph").innerHTML = "My paragraph using JS code.";
</script>

</body>
</html>
Note: Sometimes we use comments to Prevent Execution JS code

 

Multi-line Comments - example


Multi-line comments is starting with /* and end with */, text between /* and */ will be ignored by JS code.

Example:
<!DOCTYPE html>
<html>
<body>

<h1 id="my_heading"></h1>
<p id="my_paragraph"></p>

<script>
/*
The JS code will change
the heading with id = "my_heading"
and the paragraph id = "my_paragraph"
*/
document.getElementById("my_heading").innerHTML = "My title - JavaScript Comments";
document.getElementById("my_paragraph").innerHTML = "My paragraph with JS code.";
</script>

</body>
</html>

 

JavaScript Comments documentation, best practices, multiline, convention, standards, function, standard, code

JavaScript Comments documentation, best practices, multiline, convention, standards, function, standard, code
JavaScript Comments - javascript tutorial

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.