Comments

Similar to HTML's comment <!-- Comment -->, you can write comments in JavaScript that the interpreter will ignore when executing the code. Comments are create when you want to explain other humans what's going on in your very complex code. In JavaScript we have two options for writing comments.

You can use two slash characters (//). This comment will only go to the end of the line. Useful for one-line comments.

// This comment only goes to the end of the line

If you want to comment out a section of your code or text, you can use /* and */. Everything between these two will be commented out.

/*
Let's just ignore
this block of text
and this console.log() statement
console.log('I will not be printed')
*/

Your comments should explain what's going on in the code, making it easier for others to understand and maintain your code.

Last updated