src/content/docs/linter/rules/no-const-assign.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/correctness/noConstAssign`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - Sources: - Same as [`no-const-assign`](https://eslint.org/docs/latest/rules/no-const-assign){
"linter": {
"rules": {
"correctness": {
"noConstAssign": "error"
}
}
}
}
Prevents from having const variables being re-assigned.
Trying to assign a value to a const will cause an TypeError when the code is executed.
const a = 1;
a = 4;
const a = 2;
a += 1;
const a = 1;
++a;
const a = 1, b = 2;
a = 2;
const a = 10;
let b = 10;
b = 20;