JS Comments
JavaScript Comments
Ø The comments are a meaningful way to express the structure and function of the code. It is used to add information about the code structures.
Ø As the complexity of your scripts grows, comments help you (and others) understand their structure when you come to view the code at a later date.
Ø A lot of code created quickly is said to be “write-only” code, as it suffers from an inherent lack of structure or commenting.
Ø Debugging such code, or reusing it months later, becomes maddeningly impossible as you try to remember what a certain line was supposed to do, or why using certain values seems to stop your code from working.
Ø Comments are completely ignored by JavaScript and have no effect on the speed at which your scripts run, provided they are properly formed.
Ø Comments can slow the loading of your page, however – many coders keep a “development” copy of their code fully commented for editing, and remove all comments from their code when they finally publish it.
Ø There are two types of comments in JavaScript – single-line comments, and multi-line comments.
1) Single-line comments
Ø Single-line comments begin with two forward-slash characters (//) and end with a new line. It can be used before and after the statement.
// this is single line comment
console.log("hello"); // this is single line comment
2) Multi-line Comments
Ø You can add multiple-line comments by enclosing the comment block between /* and */.
/* comments are ignored by JavaScript. */
console.log("Hello World");
/* a one-line, “multi-line” comment */
Leave a comment
No Cmomments yet