Skip to content

noGlobalAssign (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"suspicious": {
"noGlobalAssign": "error"
}
}
}
}

Disallow assignments to native objects and read-only global variables.

JavaScript’s environments contain numerous built-in global variables, such as window in browsers and process in Node.js. Assigning values to these global variables can be problematic as it can override essential functionality.

Object = null;
code-block.js:1:1 lint/suspicious/noGlobalAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ A global variable should not be reassigned.

> 1 │ Object = null;
│ ^^^^^^
2 │

ℹ Assigning to a global variable can override essential functionality.

ℹ Remove the assignment, or declare a local variable with a different name and assign to that instead.

window = {};
code-block.js:1:1 lint/suspicious/noGlobalAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ A global variable should not be reassigned.

> 1 │ window = {};
│ ^^^^^^
2 │

ℹ Assigning to a global variable can override essential functionality.

ℹ Remove the assignment, or declare a local variable with a different name and assign to that instead.

undefined = true;
code-block.js:1:1 lint/suspicious/noGlobalAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ A global variable should not be reassigned.

> 1 │ undefined = true;
│ ^^^^^^^^^
2 │

ℹ Assigning to a global variable can override essential functionality.

ℹ Remove the assignment, or declare a local variable with a different name and assign to that instead.

a = 0;
let window;
window = {};