Back to JavaScript Notes
Topic #274

JavaScript Statements

By the end of this lesson, you will be able to write JavaScript statements, terminate them with semicolons, and understand when automatic semicolon insertion can safely fill in missing semicolons.

What it is

A JavaScript statement is a complete instruction that tells the engine to do something. An expression produces a value, while a statement performs an action. Variable declarations, assignments, if blocks, loops, and return are statements. A semicolon (;) marks the end of many statements. JavaScript also uses automatic semicolon insertion (ASI), which adds missing semicolons when the parser reaches a line break and the next token cannot continue the current statement, or when a restricted statement such as return is followed by a line break.

Related terms: expression, block, declaration, ASI, empty statement.

Why it matters

  • Statements are the basic units of JavaScript programs.
  • Clear termination helps avoid subtle bugs caused by ASI.
  • Statements let you store data, make decisions, repeat work, and return results.
  • Consistent semicolon style makes code easier for teams and tools to read.

Syntax or steps

The smallest useful pattern is one instruction per statement, ending with a semicolon:

let a = 1;
a = a + 1;
  1. Declare a variable with let, const, or var.
  2. Use an expression to compute a value.
  3. End the statement with ;.
  4. Use braces { } when a statement needs a block of multiple statements.

Example

let a = 1;
a = a + 1;

if (a > 1) {
  console.log("a is greater than 1");
}

let b = a * 2;
console.log(b);

Part by part:

  • let a = 1; declares a and assigns 1.
  • a = a + 1; reads a, adds 1, and stores the result back in a.
  • if (a > 1) { ... } is a control statement with a block.
  • let b = a * 2; creates a new variable from the updated value.
  • console.log(b); prints 4.

Common mistakes

  • Putting a semicolon after an if condition. if (a > 1); { ... } makes the if control an empty statement. Remove the semicolon.
  • Breaking a return statement. return followed by a line break can cause ASI to insert a semicolon, returning undefined. Keep the returned value on the same line as return.
  • Assuming every line break ends a statement. If one line ends with x = y and the next line starts with (z), JavaScript may parse it as a function call. Add a semicolon after y or use parentheses carefully.
  • Using ASI inconsistently. Some missing semicolons work, but relying on them can make code harder to predict. Use semicolons explicitly in team code.

When to use it

Compare explicit semicolons with relying on ASI:

ApproachUse whenBenefitRisk
Explicit semicolonsMost production code, especially team projectsClear intent and fewer surprisesCan feel noisy if overused
ASISmall scripts or style guides that omit semicolonsShorter codeSubtle parsing bugs in edge cases

Practice

Guided exercise: write a statement that declares count as 5, increments it by 1, and logs the result.

let count = 5;
count = count + 1;
console.log(count);

Expected output: 6.

Challenge: rewrite this code so it does not accidentally return undefined.

function makeUser() {
  return
  {
    name: "Ada"
  };
}

Solution hint: move the object literal to the same line as return.

Quick check

Question: What does ASI do?

Answer: It inserts missing semicolons when the parser reaches a line break and the next token cannot continue the current statement, or when a restricted statement such as return is followed by a line break. It does not make every line break a safe statement boundary.

Summary

JavaScript statements are complete instructions, and semicolons make their boundaries explicit. ASI can help, but relying on it can create subtle bugs, especially with return, if, and line breaks.

Want to go beyond the notes?

Join Coding Now Tech Institute's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

JavaScript Statements – FAQs

Quick answers about learning JavaScript Statements in JavaScript.

This free note from Coding Now Tech Institute explains JavaScript Statements in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on Coding Now Tech Institute, including JavaScript Statements, is 100% free with no signup required.
With focused practice, most students grasp JavaScript Statements in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now