Chapter 05
JavaScript Comments
Comments are notes inside the code that explain the program. JavaScript does not execute comments.
01 • Learn
What is JavaScript Comments?
- A single-line comment starts with //.
- A multi-line comment is written between /* and */.
- Comments help developers understand and maintain code.
- Comments are not normally displayed to users on the webpage.
02 • Syntax
Syntax
// Single-line comment /* Multi-line comment */
03 • Example
Example
Try understanding this code before running it.
// Store the student's name let name = 'Rahul'; /* Store the student's marks in a variable */ let marks = 85; console.log(name); console.log(marks);
04 • Remember
Important Points
- Use comments to explain useful or non-obvious parts of the code.
- Keep comments accurate and up to date.
- Never store passwords, API secrets, or other sensitive information in comments.
- Comments are especially useful when working on team projects.
05 • Avoid
Common Mistakes
- Forgetting to close a multi-line comment.
- Adding unnecessary comments to every line.
- Putting passwords or secret keys inside comments.
06 • Practical
Real-World Use
Professional developers use comments to explain complex logic, important decisions, and sections of a project.
07 • Practice
Practice Exercise
Practice: Comments
Add one single-line comment and one multi-line comment to your JavaScript program.
Ready to write code?
Open the JavaScript editor and run your code with live output.