single line and multi line comments in javascript and the syntax of the javascript variable creation and use it
1.JavaScript Comments:
JavaScript comments can be used to explain JavaScript code, and to make it more readable. It is used to mark what we done on this code.
There are two types of comments in JavaScript. They are
- Single line comments
- Multi line comments
1.1. Single Line Comments
Single line comments start with //
.
Any text between //
and the end of the line will be ignored by JavaScript (will not be executed).
This example uses a single-line comment before each code line:
scrpit.js:
document.getElementById("myH").innerHTML = "My First Page";
1.2. Multi-line Comments
Multi-line comments start with /*
and end with */
.
Any text between /*
and */
will be ignored by JavaScript.
This example uses a multi-line comment (a comment block) to explain the code:
scripts.js
1.3. Using Comments Effectively
Now that you know the types, let’s talk about using comments effectively. Remember, the goal is to make your code clearer to yourself and others. Here are a few tips:
- Be Concise: Write enough to explain the “why” behind your code, but keep it brief.
- Stay Relevant: Make sure your comments are always up-to-date with your code changes.
- Avoid Overcommenting: Don’t state the obvious. If the code is self-explanatory, let it speak for itself.
2.JavaScript Syntax:
JavaScript syntax is the set of rules, how JavaScript programs are constructed:
Sponsors content:
"This Content Sponsored by Genreviews.Online
Genreviews.online is One of the Review Portal Site
Website Link: https://genreviews.online/
Sponsor Content: #genreviews.online, #genreviews, #productreviews, #bestreviews, #reviewportal"
Comments
Post a Comment