LOGBOOK

HELP

Quiz Entry - updated: 2026.06.20

How are JavaScript statements terminated, and should you always use semicolons?

Statements end with a semicolon (;); JavaScript can guess where one belongs, but writing them yourself avoids surprises.

A JavaScript program is just a sequence of statements — single instructions like declaring a variable or printing a value. Each one is meant to be closed with a semicolon:

let a = 5;
let b = 3;
let result = a + b;
console.log('Result: ' + result);

That example is four statements. The language is lenient: a semicolon may be left out when the statement ends at a line break, because JavaScript will quietly insert one for you. This convenience feature is called Automatic Semicolon Insertion (ASI).

The gotcha is that ASI doesn't always guess the way you intended — a line starting with ( or [, or a return with its value on the next line, can be merged or split in ways that silently break your code. That is why the common advice is: always write semicolons explicitly. They make your intent unambiguous and sidestep ASI's occasional wrong guesses.

From Quiz: WEBT / Introduction to JavaScript | Updated: Jun 20, 2026