Writing Empty Blocks and Comments

The end-of-day release note script has its braces, but its unfinished all-clear branch still needs attention. In Python, that else branch holds pass and a TODO to link the bug tracker. You’ll port the placeholder and the script’s documentation without leaving a failure waiting for the next all-clear day.

Leave a Block Empty

Python requires pass when a block contains only a comment. Carrying it into JavaScript looks plausible.

In JavaScript, // starts a comment that runs to the end of the line. Watch out: Python’s # comment marker causes a SyntaxError before anything runs.

With the settings declared using const and console.log() printing the note, Maya’s port is:

Language: JavaScript
const BUGS_OPENED = 9;
const BUGS_CLOSED = 7;
const openBugs = BUGS_OPENED - BUGS_CLOSED;

if (openBugs > 0) {
  console.log("Open bugs:", openBugs);
} else {
  pass; // TODO: link the bug tracker
}

console.log("Note ready for Fernleaf Bakery");

With two bugs open, Maya’s run finishes:

Language: Program Output
Open bugs: 2
Note ready for Fernleaf Bakery

Theo closes the last two bugs tomorrow. Predict whether the same port still finishes when he changes BUGS_CLOSED to 9:

Language: JavaScript
const BUGS_OPENED = 9;
const BUGS_CLOSED = 9;
const openBugs = BUGS_OPENED - BUGS_CLOSED;

if (openBugs > 0) {
  console.log("Open bugs:", openBugs);
} else {
  pass; // TODO: link the bug tracker
}

console.log("Note ready for Fernleaf Bakery");

JavaScript stops with this error before printing the closing line. Only the error line is shown:

Language: Program Output
ReferenceError: pass is not defined

JavaScript has no pass keyword. It treats pass as a variable name. The lookup happens only when the branch runs, so Maya’s skipped branch hid the problem. Python also delays name lookups until execution, but its pass is a keyword.

Braces already mark an empty block’s boundaries. Remove pass and keep the comment explaining why there’s nothing to do:

Language: JavaScript
const BUGS_OPENED = 9;
const BUGS_CLOSED = 9;
const openBugs = BUGS_OPENED - BUGS_CLOSED;

if (openBugs > 0) {
  console.log("Open bugs:", openBugs);
} else {
  // TODO: link the bug tracker
}

console.log("Note ready for Fernleaf Bakery");

Theo’s all-clear run now finishes:

Language: Program Output
Note ready for Fernleaf Bakery

An empty {} needs no placeholder, even when it contains a comment. The TODO documents an intentional gap.

Document the Script With Comments

For longer notes, a block comment spans from /* to */. Python needs # on each line. Watch out: block comments can’t nest, and the first literal */ ends the comment, even inside quoted text.

For documentation, use a JSDoc comment, opening with /**, at the file’s top or directly above a function:

Language: JavaScript
/**
 * @file Print the end-of-day release note for a client's channel.
 */
/*
  Edit these settings, run the script, and paste
  the note into the client's channel.
*/
const CLIENT = "Fernleaf Bakery";
console.log("Note ready for", CLIENT);

JavaScript ignores both comments and prints:

Language: Program Output
Note ready for Fernleaf Bakery

@file marks a file description, while a function description goes directly above the function. Editors can display JSDoc on hover, especially for functions, and documentation tools read the comments too. The inner * is a readability convention. Tags such as @param and @returns describe parameters and return values, which you’ll explore later.

Python retains docstrings for help(), while JavaScript ignores JSDoc comments at runtime. Watch out: carrying over a triple-quoted docstring causes a SyntaxError too. Write documentation as a comment in JavaScript.

In the next exercise, Fix the Release Note’s Blocks, you’ll complete a teammate’s port so it prints the right end-of-day note for the client’s channel.

Become a Member to join the conversation.