JavaScript Syntax

What is JavaScript Syntax?
JavaScript syntax refers to the set of rules that define how JavaScript programs are written and understood by the browser.
Just like grammar in a language, syntax tells JavaScript how to read and execute code.
Basic Rules
1. JavaScript Statements
Each instruction is called a statement and usually ends with a semicolon (;).
2. JavaScript Variables
Variables store data. Examples:
3. JavaScript Identifiers (Names)
Names of variables, functions, etc.
Rules:
Must start with a letter,
_or$Cannot start with a number
Case-sensitive (
age≠Age)
Example:
4. JavaScript Comments
Comments are ignored by the browser.
5. JavaScript Keywords
Keywords are reserved words (cannot be variable names):
let, var, const, if, else, function, return, class, etc.
Example:
6. JavaScript Values
Two types:
| Type | Example |
|---|---|
| Literal values | 50, 3.14, "hello", true, false |
| Variables | x, name, price |
Example:
Example with Output
Output:
Case Sensitivity
JavaScript is case-sensitive:
Summary Table
| Feature | Example |
|---|---|
| Statement | let x = 10; |
| Variable | const name = "Sam"; |
| Comment | // hello |
| Case-sensitive | count ≠ Count |
