Comments are notes you add to your JavaScript code that are ignored by the JavaScript engine. They help explain logic, document your code, or temporarily disable lines.
//./* ... */.// This is a single-line commentlet x = 5; // store the initial value/* This is a multi-line comment */
// This is a single-line comment
let x = 5; // This is also a single-line comment
// Calculate the total price
let price = 100;
let quantity = 2;
let total = price * quantity;
/*
This is a multi-line comment.
It can span multiple lines.
Use it for longer explanations.
*/
let y = 10;
/*
Temporarily disable a line by turning it into a comment.
This is helpful while debugging or testing.
*/
// let result = complexCalculation(a, b);
console.log("Testing without calculation");
The console will show:
Testing without calculation
Click the button to toggle a short comment tip:
// TODO: handle invalid input.<span class="comment">.
✍️ Commenting Guidelines (for these notes)
To make comments stand out in your JavaScript notes, every comment inside a code block is wrapped in a special span:
<span class="comment">// This is a comment</span>let x = 5; <span class="comment">// store the initial value</span><span class="comment">/* multi-line comment here */</span>The CSS rule
.code-block .commentmakes these comments appear in a different color and italic style.