A JavaScript program is made up of **statements** separated by semicolons. Code blocks `{}` group statements. Identifiers are **case-sensitive** (`myVar !== myvar`). Whitespace is ignored except inside strings.
1Understanding Basic Syntax
A JavaScript program is made up of statements separated by semicolons. Code blocks {} group statements. Identifiers are case-sensitive (myVar !== myvar). Whitespace is ignored except inside strings.
Semicolons are optional due to ASI (Automatic Semicolon Insertion), but explicit semicolons prevent ambiguity bugs.
// Statements and blocks
let name = 'Alice';
let age = 30;
if (age >= 18) {
console.log(name + ' is an adult');
}2Practical Example
Here is a real-world application of Basic Syntax showing how it is used in production JavaScript code.
// Case sensitivity
let myVar = 1;
let myvar = 2;
console.log(myVar); // 1
console.log(myvar); // 23Best Practices
Follow these guidelines when working with Basic Syntax:
1. Always use curly braces for if/else blocks
2. Consistent indentation (2 or 4 spaces)
3. One statement per line
Tip: Semicolons are optional due to ASI (Automatic Semicolon Insertion), but explicit semicolons prevent ambiguity bugs.
// Statements and blocks
let name = 'Alice';
let age = 30;
if (age >= 18) {
console.log(name + ' is an adult');
}