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
0Follow one example
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.