Comments in JavaScript are primarily used to explain what the code is for or to make it more readable. Single line comments start with a double forward slash (//), but do not have an end tag. Any text that is written after (//) will be completely ignored by JavaScript and will not be executed or displayed by the browser.
Start “Tag”:
//
End “Tag”:
None
Example:
// Write to element with ID of “line”.
document.getElementById(“line”).innerHTML=”Are you sure?“;
Explanation:
Labels JavaScript code so anyone viewing will know the statement is to write to an element with an ID of “line”.
Comments in JavaScript – Tutorial: A picture describing the use of single-line comments in JavaScript.
Multi-line comments in JavaScript start with a forward slash and an asterisk (/*) and end with an asterisk and a forward slash (*/). This allows for breaking your comments up into many lines, making it more readable for later editing. Just like single line comments, multi-line comments are ignored by JavaScript and will not be displayed by browsers.
Start “Tag”:
/*
End “Tag”:
*/
Example:
/*
This is an
Example of a
Multi-line comment.
*/
Explanation:
Allows you to write comments across multiple lines that will be ignored by JavaScript and web browsers.
Comments in JavaScript: Instructions
To add a single line comment, type: //
On the same line enter the information you want as your comment.
To add multi-line comments on the line you want your comment to start, type: /*
Comments in JavaScript – Tutorial
Comments in JavaScript: Overview
Comments in JavaScript are primarily used to explain what the code is for or to make it more readable. Single line comments start with a double forward slash (//), but do not have an end tag. Any text that is written after (//) will be completely ignored by JavaScript and will not be executed or displayed by the browser.
document.getElementById(“line”).innerHTML=”Are you sure?“;
Comments in JavaScript – Tutorial: A picture describing the use of single-line comments in JavaScript.
Multi-line comments in JavaScript start with a forward slash and an asterisk (/*) and end with an asterisk and a forward slash (*/). This allows for breaking your comments up into many lines, making it more readable for later editing. Just like single line comments, multi-line comments are ignored by JavaScript and will not be displayed by browsers.
This is an
Example of a
Multi-line comment.
*/
Comments in JavaScript: Instructions
Comments in JavaScript: Video Lessons
The following video lessons, titled “Single-line Comments” and “Multi-line Comments,” show you how to create comments in JavaScript. The following video lessons are from our Introductory JavaScript course, titled “Mastering Introductory JavaScript Made Easy v.1.0.”
About Joseph Brownell
What you can read next
Free Microsoft Office Applications Online with Microsoft Office Online
@Mentions in Microsoft Teams
Change the View of a PDF in Acrobat XI Pro