Assignments to undeclared identifiers

suggest change

Assigning 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents