Splitting Long Lines

The release note’s last few lines are its longest. When the code freeze is on and bugs are still open, the note warns the client to hold tomorrow’s deploy. Then it signs off with a two-part closing message. Both lines are too long to read comfortably on one line, so the Python script splits them.

You’ve seen that JavaScript doesn’t end a statement at a newline, and that a line starting with [ can join the line above it. That same rule decides where you’re allowed to break a long line. In this lesson, you’ll port both long lines and meet the one place where a break you add to split a long line changes what your code means. Start with the code-freeze check.

Break a Long Condition

In Python, a newline ends a statement unless you’re inside brackets. That’s why the script wraps its code-freeze check in parentheses, with one test per line:

Language: Python
CODE_FREEZE = True
open_bugs = 2

if (
    CODE_FREEZE
    and open_bugs > 0
):
    print(
        "Hold tomorrow's deploy until the open bugs are closed."
    )

The JavaScript port keeps that shape, with braces around the body and && for Python’s and:

Language: JavaScript
const CODE_FREEZE = true;
const openBugs = 2;

if (
  CODE_FREEZE &&
  openBugs > 0
) {
  console.log(
    "Hold tomorrow's deploy until the open bugs are closed."
  );
}

Run it, and the note gets its warning:

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

Become a Member to join the conversation.