Code Comments

Code Comments

Write clear, useful comments in English — from inline WHY-comments to full JSDoc blocks and Python docstrings. 6 practice sets.

Quick reference

Comment types

  • Inline comment: single-line explanation after/above code
  • Block comment: multi-line explanation of a function or section
  • Docstring: structured comment attached to a function/class (JSDoc, Python)
  • TODO: planned future work ("TODO: add retry logic")
  • FIXME: known bug or broken code to fix later
  • HACK / XXX: temporary workaround; needs revisiting
  • NOTE / NB: important contextual information

The "WHY not WHAT" rule

  • i++; // increment ibad: says what the code does
  • i++; // skip the header rowgood: says why
  • Comment on intent, not mechanics
  • "We use X because Y" — provides context the code cannot show
  • Document edge cases, non-obvious algorithms, external constraints

JSDoc key tags

  • @param {type} name - description
  • @returns {type} description
  • @throws {ErrorType} when …
  • @example — usage example block
  • @deprecated — marks a function as deprecated
  • @see — cross-reference link