Skip to the workspace
Pebellslearn by building
Strict Mode  ›  Lesson

Strict Mode

Strict Mode 12 min

javascript / Strict Mode

Explore each scene at your own pace.

01 · Strict Mode

Strict Mode

Strict Mode

Strict mode enables stricter language rules that turn some silent mistakes into errors. Modules and class bodies are strict automatically.

A misspelled assignment should fail visibly instead of silently creating unintended state.

See the mechanism

Walk through the modelStrict ModeAuthored snapshots of the example; use Run below to test the code.
savedCount0
The intended binding is explicitly declared.
1 of 3

Follow one example

javascript

The directive applies when it appears in the required directive position at the beginning of a script or eligible function body. Assigning to an undeclared identifier throws in strict mode. It does not check all types or replace tests. Modern modules already use strict mode, and code editors or execution wrappers can influence which context you are testing.

Predict, change and check

Predict: What should happen if savedCount = 1 is misspelled as savedCout = 1?

Test your explanation: Try the misspelling under the directive and read the identifier named by the error. Repair the spelling instead of declaring another variable just to suppress it.

The tasks below ask you to explain that result and apply the idea to different inputs.

Apply and distinguish

Strictness is an execution-context property

A 'use strict' directive activates strict semantics in a suitable script or function directive prologue. Modules and class bodies already use strict semantics. A directive hidden after an ordinary statement is not equivalent to one in the prologue.

Strict code rejects some formerly silent mistakes, such as an assignment to an undeclared name or a failed write to a non-writable property. It also affects ordinary function this behavior. Strict mode does not statically type every value or validate an API response; continue to test the actual data contract.

Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.

Scene 1 of 2
Project context and further resources
Additional resources
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.