Skip to content

Latest commit

 

History

History
64 lines (43 loc) · 1.11 KB

no-const-assign.md

File metadata and controls

64 lines (43 loc) · 1.11 KB

eslint/no-const-assign

This rule is turned on by default.

What it does

Disallow reassigning const variables.

Why is this bad?

We cannot modify variables that are declared using const keyword. It will raise a runtime error.

Example

Examples of incorrect code for this rule:

const a = 0;
a = 1;

const b = 0;
b += 1;

Examples of correct code for this rule:

const a = 0;
console.log(a);

var b = 0;
b += 1;

How to use

To enable this rule in the CLI or using the config file, you can use:

::: code-group

oxlint --deny no-const-assign
{
  "rules": {
    "no-const-assign": "error"
  }
}

:::

References