no-const-assign

Disallow reassigning const, using and await using variables

error by default

Assigning to a variable declared with const, using or await using throws a TypeError when that line runs. The rule catches it earlier, including in branches your tests never reach.

=, compound assignments such as +=, ++ and -- all count.

This rule is on by default in JavaScript files. It's off in TypeScript files, where TypeScript reports the same mistake.

Configure#

On by default as an error. To turn it off:

bunfig.toml
[lint.rules]
"no-const-assign" = "off" # or "warn"

Examples#

example.js2 problems
const retries = 0;

function onFailure() {
  retries += 1;
}

function reset() {
  retries = 0;
}
example.jsNo problems
let retries = 0;

function onFailure() {
  retries += 1;
}

const protects the variable, not the value it holds. Changing a property is fine:

example.jsNo problems
const settings = { theme: "light" };
settings.theme = "dark";