JS Comments
JavaScript comments can be used to explain code and make it more readable.
JavaScript comments are ignored by the browser — they exist only to help you and other developers understand the code.
There are two types of comments:
| Type | Syntax | Use |
|---|---|---|
| Single-line | // your comment | Short note on one line |
| Multi-line | /* your comment */ | Longer explanations spanning multiple lines |
Try It — Comments in Action
Preview
When to Use Comments
- Explain why you wrote the code (not just what it does)
- Temporarily disable a line of code while debugging
- Add section headers to organise long scripts
Tip: Use
Ctrl + /in most code editors to quickly toggle comments on the selected line(s).