Strict Mode
In short: JavaScript's default rules (sloppy mode) let several real
mistakes pass silently — an undeclared variable quietly becomes a global,
writing to a frozen property just does nothing. The directive
"use strict";, placed at the top of a script or the top of a function
body, turns those silent failures into thrown errors, right where the
mistake happened. It also forbids a handful of confusing patterns outright,
like duplicate parameter names. Modern JavaScript modules and classes are
strict automatically; plain scripts and functions need to opt in.

Catch a missing declaration
The single most common thing strict mode catches: assigning to a name that was never declared, usually a typo for a local variable:
This throws ReferenceError: volume is not defined, immediately. Remove
the "use strict"; line, and the exact same code runs with no error at
all — it silently creates a new global property named volume. That
silent version is the dangerous one: the typo survives, and volume can
now be read or overwritten from anywhere else in the program.
Catch a write to a frozen object
Object.freeze locks an object's properties. Sloppy mode lets you "write"
to a frozen property and simply ignores it; strict mode tells you:
This throws TypeError: Cannot assign to read only property 'title'....
Without "use strict" inside the function, frozen.title = "Red Dawn";
would run, change nothing, and give no hint that anything went wrong —
frozen.title would still quietly read "Blue Hour" afterwards.
The trap: assuming strict mode is the default
Plain scripts and ordinary functions are sloppy unless told otherwise.
Forgetting the directive means every one of these checks is off, and bugs
that would have thrown immediately instead vanish into the program's
state, to resurface as confusing symptoms far from their real cause. ES
modules and class bodies are strict automatically — but a plain <script>
or a function outside one is not, until you add "use strict"; yourself.
Quick practice
What does "use strict"; volume = 80; do?
In sloppy mode (no "use strict"), what does volume = 80; do, with no prior declaration?
What happens when strict-mode code assigns to a property of a frozen object?
Where does "use strict"; need to appear to apply to a whole function?
Which of these is strict by default, without writing "use strict"?
🎯 Your turn
A function has the line volume = 80; with no let/const/var in
front — a typo for a local variable. Explain what happens when this
function runs normally, and what happens once "use strict"; is added,
and why the difference matters for catching bugs.
Write your explanation and submit it — there's no code to run here, just your reasoning.
