JavaScript code has a different shape from Python’s. Its blocks, statements, line breaks, and names follow their own rules, and code that looks right by Python’s rules can run differently. Here’s the bug check from a release-note script on a day with no open bugs, first in Python:
BUGS_OPENED = 9
BUGS_CLOSED = 9
open_bugs = BUGS_OPENED - BUGS_CLOSED
print(f"Open bugs: {open_bugs}")
if open_bugs > 0:
print("Please check the bug tracker.")
print("Triage call at 9:30 tomorrow.")
Python prints Open bugs: 0 and skips both lines under its if. Here’s a JavaScript port, indented the same way:
const BUGS_OPENED = 9;
const BUGS_CLOSED = 9;
const openBugs = BUGS_OPENED - BUGS_CLOSED;
console.log(`Open bugs: ${openBugs}`);
if (openBugs > 0)
console.log("Please check the bug tracker.");
console.log("Triage call at 9:30 tomorrow.");
When you run it with no open bugs, it still prints the second line, and there’s no error: