Skip to main content

Why comments?

Comments are notes in your code that JavaScript ignores. Use them to explain why something works a certain way — not what the code does (the code itself should be clear enough for that).

Single-line comments

Two slashes // start a single-line comment. Everything after // on that line is ignored.
Same idea, different character. // instead of #.

Multi-line comments

Wrap longer comments in /* */. Use these for explaining complex logic or temporarily disabling blocks of code.
In VS Code, select multiple lines and press Cmd+/ (Mac) or Ctrl+/ (Windows) to toggle comments on and off. This works for single-line comments — much faster than typing // on each line.

JSDoc comments

JSDoc comments start with /** and describe functions, parameters, and return values. Your editor reads them and shows helpful tooltips.
When you hover over calculateTotal anywhere in your code, VS Code shows the description, parameter types, and return type. This is especially valuable when working on a team.
JSDoc comments are optional but helpful. You don’t need to add them to every function — focus on public functions and anything with non-obvious parameters. When you later move to TypeScript, the type annotations handle much of what JSDoc does.

When to comment (and when not to)

Good comments explain intent, warn about gotchas, or provide context that the code alone can’t convey.

What’s next?

You’ve covered the fundamentals — variables, data types, strings, and comments. Now let’s make your code reusable with functions.

Functions basics

Write reusable blocks of code