Comments are notes in your JavaScript code that are ignored by the browser. They help you explain, organize, or temporarily disable code without affecting program execution.
| Comment Type | Syntax | Usage |
|---|---|---|
| Single-line Comment | // your comment here | Comments a single line or part of a line |
| Multi-line Comment | /* your comment here */ | Comments multiple lines or block of text |
Single-line comments start with // and continue to the end of the line. Use them for brief explanations or notes.
📌 Deep Dive: Single-line Comment Example
// This variable stores the user's age
let age = 30; // age in years
Multi-line comments start with /* and end with */. Use these to comment out blocks of code or write longer explanations.
📌 Deep Dive: Multi-line Comment Example
/*
This function calculates the square of a number.
It takes one parameter:
- num: a number to square
*/
function square(num) {
return num * num;
}

💡 Best Practice
Use comments to clarify complex logic or important details. Avoid obvious comments that repeat the code.
⚠️ Important
Never leave sensitive information (like passwords) in comments, as they are visible in the source code.
Comments are also invaluable for temporarily disabling code during debugging:
📌 Deep Dive: Commenting Out Code
// console.log('This line is disabled and won\'t run');
/*
console.log('This block of code');
console.log('is temporarily disabled');
*/
💡 Summary
//for single-line comments/* ... */for multi-line comments- Comments improve code readability and maintainability
- Use comments wisely to explain "why", not "what"
Quick Knowledge Check
Test what you just learned
Question 1 of 2
Which symbol starts a single-line comment in JavaScript?
Question 2 of 2
What is the main purpose of using comments in your code?
Loading results...