LESSON 03 / 07

Statements, Semicolons & Comments

How JavaScript reads your code line by line, why semicolons end statements, and how comments leave notes for humans.

๐ŸŽ“Beginnerlevel
โฑ๏ธ20 minto finish
โœ๏ธ2activities

๐Ÿ“‚ First Steps in JavaScript๐Ÿท๏ธ JavaScript basics

๐ŸŽฏ By the end of this lesson you canโ€ฆ

  • Recognise statements and where they end
  • Write single-line and multi-line comments
  • Use comments to explain and to switch code off

One instruction at a time

A statement is one complete instruction, like one sentence. JavaScript runs statements from top to bottom.

โšก JavaScript order.js ๐Ÿ‘† Tap a line to explain it
1console.log("1. Wake up");2console.log("2. Brush teeth");3console.log("3. Eat breakfast");

Comments: notes for humans

โšก JavaScript comments.js ๐Ÿ‘† Tap a line to explain it
1// This is a single-line comment. The computer skips it.2const tax = 0.18; // comments can also sit at the end of a line3 4/*5  This is a multi-line comment.6  Great for longer explanations.7*/8console.log(100 + 100 * tax);9// console.log("switched off");
๐Ÿ’ก Concept check
What does the computer do with // total price ?
๐Ÿ› ๏ธ Uncomment to fix

The program should print Ready then Set then Go!, but one line has been commented out. Fix it.

๐Ÿ“Œ Key takeaways

  • A statement is one instruction; it usually ends with ;.
  • // comment and /* comment */ are ignored by the computer.
  • Code runs from top to bottom, one statement at a time.

Finished reading & practising?

Saved in this browser. Create a free account to keep it forever.