A JavaScript statement is a single instruction that tells the engine to perform an action. Programs consist of statements executed in order from top to bottom, grouped inside curly-brace code blocks.
Beginners often mix up statements and expressions, yet the difference is simple. An expression produces a value, while a statement performs an action such as declaring a variable or controlling flow.
For example, 25 * 2 is an expression because it evaluates to 50. Writing const price = 25 * 2; is a statement because it binds that result to price.
JavaScript groups related statements inside { ... } blocks for functions, loops, and if conditions. Semicolons mark the end of individual statements.
function calculateDiscount(subtotal) {
let rate = 0;
if (subtotal >= 100) {
rate = 0.15;
} else {
rate = 0.05;
}
const finalPrice = subtotal * (1 - rate);
return finalPrice;
}
console.log("Final price:", calculateDiscount(120));
JavaScript engines insert missing semicolons at most line breaks through Automatic Semicolon Insertion. However, relying on ASI everywhere can trigger silent bugs when a line starts with (, [, or a template literal, or when return has a newline before its value.
return: Writing return on one line and the object { ok: true } on the next line makes JavaScript return undefined.[ without a semicolon: Without a semicolon on the prior line, JavaScript may treat [1, 2].forEach(...) as property access on the previous expression.No, JavaScript does not require semicolons on every line because of Automatic Semicolon Insertion. Still, most engineering teams keep explicit semicolons to prevent edge-case parsing bugs.
Yes, separating statements with semicolons allows multiple instructions on one line, such as let x = 1; let y = 2;. Keeping one statement per line is much easier to read and debug.
JavaScript ignores extra spaces and tabs between tokens. Use consistent two-space indentation inside code blocks to keep nested logic clear.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.