Spelling Rules
Like any language, JS has its own " punctuation. "
1. Semicolons ;
JS has a mechanism called ASI (Automatic Semicolon Insertion) — it automatically places semicolons if you forget them.
Caution
ASI is a tricky helper. Sometimes it breaks a line where you didn't plan it, causing weird errors.
Golden Rule: While learning, explicitly place a ; at the end of every command.
2. Modern Mode: " use strict "
In 2009, JavaScript got a major update, but to prevent old sites from breaking, old mistakes were left " by default " . To turn them off and use the modern standard, write this on the first line of your file:
"use strict";
This mode:
- Forbids using undeclared variables.
- Makes code slightly faster (easier for the engine to analyze).
- Throws errors where old JS simply ignored them.
Note
You cannot " turn off " strict mode in the middle of a file. It's " all or nothing. " In modern code with modules (which we will learn later), it is enabled automatically.