J

JavaScript Tutorial

Clean • Professional

JavaScript Comments

1 minute

JavaScript Comments

JavaScript comments are notes in your code that the computer ignores. They help explain your code, remind you why you wrote it, or guide teammates—like sticky notes for programmers.

Why Use Comments?

  • Explain what your code does (e.g., “Calculate total price”).

  • Remind yourself of important details (e.g., “Fix bug later”).
  • Temporarily disable code while testing.
  • Make code professional and team-friendly (a must-have skill in 2025).

Types of JavaScript Comments

1. Single-Line Comments (//)

A single-line comment starts with //. Everything after it on the same line is ignored.

// This prints a greeting
console.log("Hello, World!");

// Disable a line temporarily
// console.log("This won’t run");
console.log("Code still works!");

2. Multi-Line Comments (/* ... */)

A multi-line comment starts with /* and ends with */.

Everything between is ignored—even across multiple lines.

/* This block of code
   calculates total price with tax */
let price = 100;
let tax = price * 0.1;
console.log(price + tax);

/* Temporarily disable multiple lines
let x = 10;
console.log(x);
*/
console.log("Only this runs!");

 

Article 0 of 0