JavaScript Statements

Statements, semicolons and code blocks.

✍️ 3 exercises + code challenge in this lesson

A JavaScript program is a list of statements that the browser executes one by one, top to bottom.

  • Statements are separated by semicolons ;. They are optional in most cases but recommended.
  • Extra spaces and line breaks are ignored, so format code for readability.
  • Statements can be grouped in code blocks with curly braces { }.
  • Keywords such as let, if, for, function and return start statements.

Key Takeaways: JavaScript Statements

Mastering JavaScript Statements helps you write clean and reliable JavaScript code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

JavaScript Statements Code Example

JavaScript
<pre id="out"></pre>
<script>
const log = (...a) => document.getElementById("out").textContent += a.join(" ") + "\n";
let a = 5;
let b = 6;
let c = a + b;
log("a + b =", c);

{
  // A code block
  let message = "Inside a block";
  log(message);
}
</script>
Free sign-in required · Google login available

JavaScript Statements Practice Exercises

Check what you learned in “JavaScript Statements”.

/ 3 solved
Fill in the blank

End the statement correctly.

let total = 5 + 3
✓ Correct! Not quite. Try again.
Multiple choice

How are JavaScript statements executed?

✓ Correct! Not quite. Try again.
Code challenge

Create a = 4 and b = 6 and log their product.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services