Ending Statements With Semicolons
In this lesson, you found out what ends a statement in JavaScript, and why the release note’s handover stopped when it was ported without semicolons.
- In JavaScript, a semicolon ends a statement, not a newline.
- With no semicolon, JavaScript usually fills one in when the next line can’t carry on the
statement, as with the
letafter"Maya"here. That’s automatic semicolon insertion. - So a newline isn’t always the end. After a value, a line that starts with a square bracket can carry on, and the two lines join into one statement.
- JavaScript with no semicolons is a real style that relies on the insertion rule. This course
writes them, which keeps this swap separate from the line above. A line break straight after
returnstill ends the statement, whatever semicolons you write, as Splitting Long Lines shows. A formatter, a layout tool a bit like Black in Python, then keeps the semicolons in place.
Here’s the Python handover. It swaps today’s and tomorrow’s deployer in one line:
deployer = "Maya"
next_deployer = "Theo"
deployer, next_deployer = next_deployer, deployer
print("Next:", deployer, "then", next_deployer)