Comments
Comments let you leave notes in your code. They are ignored by JavaScript and exist only for humans reading the code.
Single-line Comments
Use // to comment out a single line:
// This is a comment
console.log('Hello') // This prints Hello
Multi-line Comments
Use /* */ to comment out multiple lines:
/*
This is a multi-line comment.
JavaScript ignores all of this.
*/
console.log('World')
Why Comments Matter
Good code should be self-documenting — readable without needing many comments. But comments are useful for:
- Explaining why something is done (not just what)
- Temporarily disabling code while debugging
- Marking TODOs and FIXMEs
⚠️ Avoid obvious comments
Don't write // adds 1 to x before x = x + 1. Comments should add value, not repeat what the code already says.