Comments (Single-line & Multi-line)
Comments: Your Code’s Notes
Comments are like sticky notes in your code. They help you and others understand what your code does, but the browser ignores them completely.
Single-line Comments
Use //
for comments that fit on one line:
Copy to Clipboard
Multi-line Comments
Use /* */
for comments that span multiple lines:
Copy to Clipboard
Why Use Comments?
- Explain what your code does
- Help others understand your code
- Remind yourself what you were thinking
- Temporarily disable code without deleting it
Tip: Good comments explain the “why,” not the “what” – the code already shows what it does!