Strict Mode
Strict mode tells JavaScript to follow safer rules.
It catches quiet mistakes and turns them into clear errors.
Think of a teacher who asks you to write carefully.
How to turn it on
No accidental globals
No duplicate params
Why safer rules help
Turn it on
Put "use strict"; at the top of a file or function.
Stops accidental globals
In sloppy mode, assigning to a missing name can create a global.
In strict mode, that is an error.
Cleaner function rules
Strict mode blocks some confusing function tricks.
Duplicate parameter names are not allowed.
this stays undefined in plain functions
In a normal function call, this is undefined in strict mode.
That prevents accidental use of the global object.
Modules are strict already
JavaScript modules run in strict mode by default.
Many project files already get these safer rules.
Tip: Keep "use strict" at the top while you learn. It turns sneaky bugs into loud lessons.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.