JS Tutorial



JS COMMENTS


JavaScript Comments

In JavaScript, comments are used to explain code, make notes, or prevent certain parts from running. Comments are ignored by the browser and do not affect how the code works.

✨ Tip: Use comments to make your code easier to understand for yourself and others.

✍️ Types of Comments

JavaScript supports two types of comments:

  • Single-line comments β†’ Start with //
  • Multi-line comments β†’ Start with /* and end with */

πŸ“Œ Examples:

// This is a single-line comment
let name = "John"; // This is an inline comment

/* 
  This is a multi-line comment.
  It can span multiple lines.
*/
let age = 30;
  

πŸ§ͺ Live Example:

Click the button to see how comments are ignored by JavaScript:

Output will appear here

🧠 Best Practices

  • Use comments to describe why something is done, not what is done (the code shows *what*).
  • Don't overuse commentsβ€”clean, readable code is more powerful than too many notes.
  • Use multi-line comments for section summaries or longer explanations.
πŸ“š Summary: JavaScript comments help you document and understand your code. Use // for single lines and /* */ for blocks.

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review