Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Porting the Release Note

Porting the Release Note

In this project, you ported the release note script to JavaScript, checked it, and ran it. Two parts are left for the exercise after this video: the code-freeze warning, which reads the code-freeze setting, and the closing message.

  • JavaScript has no docstrings, so the docstring becomes a JSDoc block, a block comment that opens with an extra star. The # comment turns into //.
  • Each setting gets a const and keeps its capitals, as many projects write top-level settings that someone edits. In Python, nothing stops you reassigning a setting; const makes JavaScript refuse a second assignment. Watch out for Python’s capital True: JavaScript writes true and false in lowercase, and True would stop the file with a reference error before it printed anything.
  • open_bugs becomes camelCase, openBugs, and stays a const, since nothing reassigns it.
  • The status line is a let, and an if-else block sets it. Python’s line is a one-line conditional expression, but JavaScript’s if is a statement, so it can’t sit on the right of an =. JavaScript has a shorter form for this, which you’ll meet later; for now, an if/else does it.
  • The two prints turn into console.log() calls, each f-string a template literal.
  • The bug check keeps its if and else, in braces. Its if has one line, and the port braces it anyway, so a line someone adds later lands inside the block.
  • The else holds only a pass placeholder and a reminder. Empty braces are already a block, so the port drops pass and keeps the reminder inside as a comment. JavaScript has no pass: it would read it as a name and stop on the first day with no open bugs.
  • Both deployers are lets, because the swap reassigns them, and the swap becomes destructuring, with square brackets on both sides. Each plain statement ends with a semicolon, and the one after "Theo" matters most, because the next line starts with a bracket. Without it, the two lines would join: the bracket would index the string, and the run would stop with an error.

Here’s the port, release-note.js, with the code-freeze warning and the closing message still to come:

Language: JavaScript
/**
 * Print the end-of-day release note.
 */

// Edit these settings before each run.
const CLIENT = "Fernleaf Bakery";
const VERSION = "2.4.1";
const DEPLOYED_BY = "Maya";
const BUGS_OPENED = 9;
const BUGS_CLOSED = 7;
const CODE_FREEZE = true;

const openBugs = BUGS_OPENED - BUGS_CLOSED;
let statusLine;
if (openBugs === 0) {
  statusLine = "all clear";
} else {
  statusLine = "needs attention";
}
console.log(`Release ${VERSION} for ${CLIENT}`);
console.log(`Status: ${statusLine}`);

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

let deployer = DEPLOYED_BY;
let nextDeployer = "Theo";
[deployer, nextDeployer] = [nextDeployer, deployer];
console.log("Next:", deployer, "then", nextDeployer);

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:02 In this project, you’ll port the release note script to JavaScript, check it, and run it. Here’s the Python script: six settings, the status line, the bug check, and the deployer swap, and running it prints the note.

00:18 Two parts are left for the exercise after this video: the code freeze warning, which reads the code freeze setting, and the closing message.

00:28 Start at the top. JavaScript has no docstrings, so the docstring becomes a JSDoc block, a block comment that opens with an extra star. The hash comment turns into two slashes.

00:43 Each setting gets a const and keeps its capitals, as many projects write top-level settings that someone edits. In Python, nothing stops you reassigning a setting; const makes JavaScript refuse a second assignment.

00:58 One value changes. Watch out for Python’s capital True. JavaScript writes true and false in lowercase, and True would stop the file with a ReferenceError before it printed anything.

01:12 open_bugs becomes camel case, and stays a const, since nothing reassigns it. The status line lands as a let, and an if…else block sets it.

01:24 Python’s line is a one-line conditional expression, but JavaScript’s if is a statement, so it can’t sit on the right of an equals sign. JavaScript has a shorter form for this, which you’ll meet later; for now, an if…else does it.

01:39 The two prints turn into console.log() calls, each f-string a template literal.

01:46 The bug check keeps its if and else, in braces. Its if has one line, and the port braces it anyway, so a line someone adds later lands inside the block.

01:58 The else holds only a pass placeholder and a reminder. In JavaScript, empty braces are already a block, so the port drops pass and keeps the reminder inside as a comment.

02:10 JavaScript has no pass. It would read it as a name and stop on the first day with no open bugs.

02:19 At the end comes the handover. Both deployers are lets, because the swap reassigns them. The swap becomes destructuring, with square brackets on both sides.

02:31 Each plain statement ends with a semicolon, and the one after Theo matters most, because the next line starts with a bracket. Without it, the two lines would join: the bracket would index the string, and the run would stop with an error.

02:47 First, check the file with node --check, which parses it and runs nothing. It prints nothing at all, so the syntax is valid. Now run it, and the note comes out in four lines.

03:02 Each one matches its line in Python’s note, needs attention included.

03:08 So the rule is: port one kind of line at a time, keeping the logic and changing the syntax, then check the file and run it.

03:17 Next up is the exercise Finish the Release Note. You’ll write the code freeze warning and the closing message the JavaScript way, and check them against the Python script’s output.

Become a Member to join the conversation.