JavaScript Tutorial · JavaScript Basics · Lesson 3 of 44
JavaScript Syntax
Statements, semicolons, code blocks and case sensitivity.
Statements
A JavaScript program is a list of statements, run from top to bottom. Statements usually end with a semicolon ;.
let x = 5;
let y = 6;
let z = x + y;
console.log(z);
Output
11
Semicolons are mostly optional — JavaScript inserts them automatically at line ends — but most style guides use them to avoid surprises.
Code blocks
Curly braces { } group statements into a block, for example the body of an if or a function. Indentation is only for humans — but always indent consistently (2 spaces is the most common style in JavaScript).
let temperature = 31;
if (temperature > 30) {
console.log("It's hot");
console.log("Drink water");
}
console.log("Done");
Output
It's hot Drink water Done
Case sensitivity and identifiers
JavaScript is case-sensitive: total, Total and TOTAL are different names. Names (identifiers) may contain letters, digits, _ and $, but cannot start with a digit. The convention is camelCase: firstName, totalPrice, isLoggedIn.
Test yourself
Are myName and myname the same variable in JavaScript?
YesNo
Show answer
Answer: No
JavaScript is case-sensitive, so they are two different identifiers.