Last updated
JavaScript Syntax
Definition: Syntax is the set of rules for writing the language. A JavaScript program is a list of statements the browser runs one at a time, top to bottom.
Example 1 — statements and semicolons
Each statement usually ends with a semicolon ;. They are mostly optional, but adding them is a safe habit:
let x = 5; let y = 6; let z = x + y; console.log(z);
Example 2 — case sensitivity
myName and myname are two different things:
let myName = "Sam"; let myname = "Alex"; console.log(myName, myname);
Example 3 — spaces and line breaks are ignored
Extra spacing does not change behaviour, so use it to stay readable:
let price = 5; let quantity = 3; let total = price * quantity; console.log(total);
💡 Convention: JavaScript names use camelCase — first word lowercase, capitalise each next word: firstName, totalPrice.
Try it Yourself
Output
Ad · responsive