JavaScript Comments

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.

Example:

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.

Example:

/*
let k=2;
let f=3;         
let g=k+f;
console.log(g)
*/
console.log("Uncommented")  

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.
Mon, 09/06/2021 - 11:30

Authored by

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.
Tags