JavaScript Comments

Profile picture for user arilio666

Is your code clumsy? or do you need to avoid certain code steps in-between? In Javascript, we have a comment option just like any other programming language. We can comment a code using two ways :

  1. Single line comment (//)
  2. Multi-line comment(/* */)

1. Single line comment

A Single-line comment comments out a solo line in a code.


console.log("Hello World")
//console.log("Hello World")   

2. Multi-line Comment

  • A Multi-line comment comments out multiple lines of code.
  • Using /* before a code comments out the rest of the code you are writing down to the point of infinite. 
  • Use */ up to the point of code you want the comment to end and continue normal coding afterward.


let k=2;
let f=3;         
let g=k+f;

Why Comments?

  • In any programming, language comments are used to prevent any unwanted executions and make the code more readable.
  • In the comments, you can also give what the code is about as a description.
  • You can simply use comments and write pseudocode to actually take reference on what you are doing.
  • With Comments, you can notify and explain to any people with less knowledge on coding what actually you are doing in the code.
  • Comments are a big stress relief for yourself to review the code after a long time.