Statements & Comments

Statements

Example

A program is a list of statements, executed one by one from top to bottom. Semicolons separate statements:

let a = 5;          // statement 1
let b = 6;          // statement 2
let c = a + b;      // statement 3
console.log(c);     // statement 4

Output

11

Comments

Example

Comments are ignored when the code runs. Use them to explain why, not what:

// single-line comment
/*
  multi-line
  comment
*/
let total = 100; // VAT is added at checkout, not here
console.log(total);

Output

100

Semicolons and Case Sensitivity

  • JavaScript inserts missing semicolons automatically (ASI), but it can guess wrong. Most style guides either always write them or use a formatter like Prettier.
  • JavaScript is case sensitive: lastName and lastname are different variables.
  • Identifiers use camelCase by convention: firstName, getUserById.