Missing Semicolon
Quick summary
You omitted a semicolon and JavaScript's automatic insertion guessed wrong, causing unexpected behavior.
Why this happens
Omitting semicolons at the end of statements
Starting a line with [ or ( after a statement without a semicolon
Relying on ASI in ambiguous contexts
Minimal example
const a = 5
const b = 10
[a, b].forEach(console.log) // ASI fails — a is 5, then [a, b] is misreadconst a = 5;
const b = 10;
[a, b].forEach(console.log); // Semicolons make boundaries clearWithout semicolons, JavaScript may interpret const b = 10[a, b] as a single expression (accessing index [a, b] on 10). Adding semicolons makes statement boundaries explicit.
How to diagnose
Check if the error message mentions an unexpected token
Look at the line before the error — a missing semicolon there may be the cause
Run a linter that enforces semicolons
How to fix
Add the missing semicolon at the end of the statement
Use a formatter (Prettier) that adds semicolons automatically
Never start a line with [ or ( without a semicolon on the previous line
How to prevent
Always use semicolons explicitly
Use a linter and formatter that enforce semicolon style
Related Resources
Related Glossary
Related Lessons
- How Programs Work
Learn about statement structure.