Tutorial
Comments Out

Comment Out Code

🎉

Read This on Github

This article is available on Github. You can read it there and contribute to it.
Github Link
Any Issue ?

➡️ Comment Out Code

Comment Out Code

In JavaScript, there are two main ways to comment out code: single-line comments and multi-line comments.

⭐ Single-Line Comments -

  • Single-line comments start with two forward slashes (//) and continue to the end of the line. Single-line comments are useful for adding notes to your code.

For example, the following code uses a single-line comment to explain what the code does:

// This is a single-line comment
console.log('Hello, World!');

⭐ Multi-Line Comments

  • Multi-line comments start with a forward slash and an asterisk (/) and end with an asterisk and a forward slash (/). Multi-line comments are useful for temporarily disabling code.

For example, the following code uses a multi-line comment to temporarily disable the console.log() method:

/* This is a multi-line comment
console.log('Hello, World!');
*/

⭐ Comment out blocks of code using the "console.log()" function

  • You can comment out blocks of code using the "console.log()" function. This is useful for temporarily disabling code.
console.log(1 + 1); // Output: 2
 
// console.log(2 + 2);
 
console.log(3 + 3); // Output: 6
 

In this example, the second line of code has been commented out using the "console.log()" function. When the code is executed, the second line will be ignored and the output will be 2 and 6.