globalAssignments
Reports attempting to assign to read-only global variables such as undefined, NaN, Infinity, Object, etc.
✅ This rule is included in the ts untyped
preset.
Global variables like undefined
, NaN
, Infinity
, and built-in objects like Object
and Array
are read-only and should not be modified.
Attempting to reassign these globals can lead to confusing behavior and potential bugs in your code.
In strict mode, reassigning these globals will throw a TypeError at runtime.
Examples
Section titled “Examples”undefined = 1;
NaN = 42;
Infinity = 100;
Object = null;
Array = function () {};
let count = 5;undefined += count;
NaN++;
--Infinity;
let myUndefined = 1;
const notANumber = 42;
const infiniteValue = 100;
let myObject = null;
const myArray = function () {};
let count = 5;let undefinedValue = undefined;undefinedValue = count;
let notANumber = NaN;notANumber++;
let infiniteValue = Infinity;--infiniteValue;
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”This rule should always be enabled, as attempting to reassign read-only global variables is always incorrect behavior in JavaScript and TypeScript. Modern JavaScript environments enforce these restrictions in strict mode, and violating them can cause runtime errors.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noGlobalAssign
- Deno:
no-global-assign
- ESLint:
no-global-assign
- Oxlint:
eslint/no-global-assign
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.