Any valid expression followed by semicolon (ASI applies)
x = 5; 2 + 2;
Declaration Statement
var/let/const name;
Declares variables with specific scope and mutability
let x; const y = 10;
Block Statement
{ statements }
Groups multiple statements; creates block scope for let/const
{ let x = 1; }
Empty Statement
;
Does nothing; useful in loop bodies or as placeholder
while(condition);
Labeled Statement
label: statement
Adds identifier to statement for break/continue targeting
loop1: for(...) {...}
Function Declaration
function name() {}
Hoisted function definition, available before declaration
function add(a,b) { return a+b; }
Class Declaration
class Name {}
Declares class; not hoisted like functions
class User { constructor() {} }
Import Statement
import x from 'mod';
Loads module exports; hoisted and executed first
import { func } from './module';
Export Statement
export default x;
Exposes values/functions from module
export { func, var };
Example: Statement types in action
// Expression statementsx = 5;y = x + 10;// Block statement with local scope{ let blockScoped = 'local'; const PI = 3.14159;}// Labeled statement for loop controlouter: for (let i = 0; i < 3; i++) { for (let j = 0; j < 3; j++) { if (i === 1 && j === 1) break outer; }}
ASI (Automatic Semicolon Insertion): JavaScript automatically inserts semicolons in certain
cases, but relying on it can cause bugs. Always use explicit semicolons for clarity.
2. Variable Declarations (var, let, const)
Declaration
Scope
Hoisting
Reassignment
Redeclaration
TDZ
var LEGACY
Function scope
Yes (undefined)
✓ Allowed
✓ Allowed
✗ No
let ES6
Block scope
Yes (uninitialized)
✓ Allowed
✗ SyntaxError
✓ Yes
const ES6
Block scope
Yes (uninitialized)
✗ TypeError
✗ SyntaxError
✓ Yes
Feature
var
let
const
Global Object Property
✓ Creates property on window/global
✗ Does not create property
✗ Does not create property
Loop Binding
Single binding (shared)
New binding per iteration
New binding per iteration
Initialization Required
✗ Optional
✗ Optional
✓ Required at declaration
Object/Array Mutation
Allowed
Allowed
Allowed (reference is const)
Example: Variable declaration differences
// var: function-scoped, hoistedconsole.log(x); // undefined (hoisted)var x = 5;if (true) { var x = 10; // Same variable}console.log(x); // 10// let: block-scoped, TDZ// console.log(y); // ReferenceError: Cannot access before initializationlet y = 5;if (true) { let y = 10; // Different variable console.log(y); // 10}console.log(y); // 5// const: block-scoped, immutable bindingconst z = 5;// z = 10; // TypeError: Assignment to constantconst obj = { a: 1 };obj.a = 2; // ✓ OK: mutation allowed// obj = {}; // ✗ TypeError: reassignment not allowed
Warning:const creates an immutable binding, not an
immutable value. Object properties can still be modified.
3. Identifier Rules and Naming Conventions
Rule
Description
Valid Examples
Invalid Examples
First Character
Letter (a-z, A-Z), underscore (_), or dollar sign ($)
_var, $elem, myVar
1var, -name, @value
Subsequent Characters
Letters, digits (0-9), underscore, dollar sign
var1, _temp2, $el3
my-var, my.var, my var
Case Sensitivity
JavaScript is case-sensitive; myVar ≠ myvar
myVar, MyVar, MYVAR
All are different variables
Unicode Support
Unicode letters allowed (international characters)
Warning: While some keywords like undefined and NaN are not
technically reserved, they reference global properties and should not be used as variable names to avoid
confusion.
Section 1 Summary
JavaScript uses various statement types for different purposes
(expressions, declarations, blocks)
Use let/const over var for block scoping and better error
detection
Follow naming conventions: camelCase for variables/functions, PascalCase
for classes, UPPER_SNAKE_CASE for constants
JSDoc comments provide type information and documentation for better IDE
support
Strict mode catches common mistakes and prevents unsafe actions
(auto-enabled in modules/classes)
Avoid using reserved keywords as identifiers; they're reserved for language
features