Notes That JavaScript Ignores
JavaScript Comments
How to write notes inside your code — for your future self, and for the developers who come after you.
What you'll learn
- Write single-line and multi-line comments
- Use comments to disable code temporarily
- Know when to comment (and when not to)
Comments are notes you write inside your code. JavaScript skips them completely — they exist for human readers.
Single-line Comments
Everything after // on the same line is a comment.
// This is a single-line comment.
let total = 0; // Comments can also follow code on the same line.
console.log(total); Multi-line Comments
Wrap multi-line notes in /* … */.
/*
This is a multi-line comment.
Useful for longer explanations
or for temporarily disabling
several lines at once.
*/
let price = 9.99;
console.log(price); Commenting Out Code
A handy trick while debugging: stick a // in front of a line to
disable it without deleting it.
let count = 10;
count = count + 1;
// count = count * 2; ← temporarily disabled
console.log(count); // 11 When to Comment
Good code uses clear names so the what is obvious. That leaves comments for the why: a constraint, a workaround, a non-obvious decision.
A good comment ages well. A comment that explains what the code does becomes a lie the moment someone refactors. A comment that explains why stays true.
Up Next
You’ve seen output, statements, syntax, and comments. Time for the single most useful tool in any programming language: variables.
JavaScript Variables →