Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Comments and documentation

Comments describe code intent without executing their contents. Learn // and /* ... */ syntax, the /** ... */ documentation convention, and how line terminators can affect program parsing.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

// comment
/* block comment */
/** documentation comment */

Comments explain code, especially the reasons behind decisions and constraints. Their contents are not executed as JavaScript. Editorial recommendation: explain “why” rather than repeating what an obvious statement does.

// starts a comment that extends to the end of the line or source; the line terminator is not part of the comment. /* ... */ can occupy part of a line or multiple lines and ends at the first */. Block comments cannot nest.

/** ... */ is an ordinary block comment to ECMAScript. Documentation notation does not change function behavior or enforce types; interpreting additional annotations is a tooling concern, not part of the language syntax.

Comments behave like white space, with an important exception: a block comment containing a line terminator is treated as a line terminator during syntactic parsing. This can affect automatic semicolon insertion (ASI), for example after return. Do not separate return from its returned value with such a comment. The separate #! form is permitted only at the very beginning of Script or Module source text.

Examples

/** Compute the total price. */
function total(price, quantity) {
  // Keep the calculation in one place.
  return price * quantity;
}

const result = total(7, /* quantity */ 3);
console.log(result);

Result

21

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources