JavaScript tutorials for Beginners – JavaScript Comments

Hits: 30



(JavaScript Tutorials for Beginners)

In this end-to-end example, you will learn – JavaScript tutorials for Beginners – JavaScript Comments.


JavaScript is a powerful and flexible programming language. It can execute on a web browser that allows us to make interactive web-pages such as popup menus, animations, form validation etc.

JavaScript has evolved a lot in the past decade. Our JavaScript tutorials will help you understand the core concepts of modern JavaScript one step at a time.

JavaScript Comments

In this tutorial, you will learn about JavaScript comments, why we use them, and how to use them with the help of examples.

JavaScript comments are hints that a programmer can add to make their code easier to read and understand. They are completely ignored by JavaScript engines.

There are two ways to add comments to code:

  • // – Single Line Comments
  • /* */ -Multi-line Comments

Single Line Comments

In JavaScript, any line that starts with // is a comment. For example,

name = "Jack";

// printing name on the console
console.log("Hello " + name);

Here, // printing name on the console is a comment.

You can also use single like comment like this:

name = "Jack";

console.log("Hello " + name);  // printing name on the console

Multi-line Comments

In Javascript, any text between /* and */ is also a comment. For example,

/* The following program contains the source code for a game. 

For the player controlling the tiger to win, they must capture all the sheep. There are altogether 4 tigers on the board.

For the sheep to win, all tigers must be surrounded and cornered so that they cannot move. The player controlling the sheep has 20 sheep at his disposal.

Since the rest of the source code will be used to implement the rules of the game, the comment above is a good example where you might use a multi-line comment.

Using Comments for Debugging

Comments can also be used to disable code to prevent it from being executed. For example,

console.log("some code");
console.log("Error code);
console.log("other code");

If you get an error while running the program, instead of removing the error-prone code, you can use comments to disable it from being executed; this can be a valuable debugging tool.

console.log("some code");
// console.log("Error code);
console.log("other code");

Pro Tip: Remember the shortcut for using comments; it can be really helpful. For most code editors, it’s Ctrl + / for Windows and Cmd + / for Mac.

Make Code Easier to Understand

As a JavaScript developer, you will not only write code but also may have to modify code written by other developers.

If you write comments on your code, it will be easier for you to understand the code in the future. Also, it will be easier for your fellow developers to understand the code.

As a general rule of thumb, use comments to explain why you did something rather than how you did something, and you are good.

Note: Comments shouldn’t be the substitute for a way to explain poorly written code in English. You should always write well-structured and self-explanatory code. And, then use comments.



Personal Career & Learning Guide for Data Analyst, Data Engineer and Data Scientist

Applied Machine Learning & Data Science Projects and Coding Recipes for Beginners

A list of FREE programming examples together with eTutorials & eBooks @ SETScholars

95% Discount on “Projects & Recipes, tutorials, ebooks”

Projects and Coding Recipes, eTutorials and eBooks: The best All-in-One resources for Data Analyst, Data Scientist, Machine Learning Engineer and Software Developer

Topics included: Classification, Clustering, Regression, Forecasting, Algorithms, Data Structures, Data Analytics & Data Science, Deep Learning, Machine Learning, Programming Languages and Software Tools & Packages.
(Discount is valid for limited time only)

Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.

Learn by Coding: v-Tutorials on Applied Machine Learning and Data Science for Beginners

Please do not waste your valuable time by watching videos, rather use end-to-end (Python and R) recipes from Professional Data Scientists to practice coding, and land the most demandable jobs in the fields of Predictive analytics & AI (Machine Learning and Data Science).

The objective is to guide the developers & analysts to “Learn how to Code” for Applied AI using end-to-end coding solutions, and unlock the world of opportunities!


C++ for Beginners: C++ Comments

Kotlin tutorial for Beginners – Kotlin Comments

Snowflake for Beginners – Create Table With Column And Table Comments