Assignments to undeclared identifiers
suggest changeAssigning to an undeclared identifier is not a variable declaration. In a legacy classic script running in sloppy mode, such an assignment may create a property on the global object:
accidentalGlobal = 12;
console.log(globalThis.accidentalGlobal); // 12
Strict mode and ECMAScript modules reject the assignment:
"use strict";
accidentalGlobal = 12; // ReferenceError
This difference helps strict mode expose misspelled identifiers instead of silently modifying global state:
"use strict";
let total = 0;
totla = 17; // ReferenceError: totla is not defined
Declare bindings explicitly with const or let. If shared global state is genuinely required, access an intentional property through globalThis so the dependency is visible:
globalThis.applicationState = { ready: false };
Modules and strict mode do not prevent code from explicitly changing properties that already exist on globalThis; they prevent the special sloppy-mode behavior for unresolved assignment targets.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents