Syntax
The rules that define correctly structured JavaScript programs.
Syntax
let identifier = value;Syntax is the set of rules for how a program is written. A JavaScript program is a list of instructions called statements.
Values and identifiers
- Fixed values (literals) like
10or'Hello'. - Variable values stored using names (identifiers) like
xorprice.
JavaScript is case-sensitive: myName and myname are two different names.
Example
Loading editor…
Press Run to execute the code.
When to use it
- Follow consistent semicolon and casing rules across a team codebase enforced by ESLint.
- Avoid accidental variable shadowing by using proper block scoping with curly braces.
- Write readable code by separating statements on individual lines per your style guide.
More examples
Case-sensitive identifiers
Demonstrates that JavaScript identifiers are case-sensitive, so userName and username are two distinct variables.
let userName = "Alice";
let username = "bob"; // different variable
console.log(userName, username);Semicolons and line breaks
Shows conventional use of semicolons to terminate statements, making the code unambiguous for parsers.
const a = 10;
const b = 20;
const sum = a + b;
console.log(sum); // 30Block scope with curly braces
Illustrates how curly braces define a block scope that limits where let-declared variables are accessible.
{
let blockVar = "only here";
console.log(blockVar); // "only here"
}
// console.log(blockVar); // ReferenceError outside block
Discussion