Disallow reassigning const variables


ID: javascript-best-practices/no-const-assign

Language: JavaScript

Severity: Error

Category: Best Practices


In JavaScript, assigning to a const variable is an error and causes an exception to be thrown at runtime. This rule disallows assigning to constant variable declarations.

Non-Compliant Code Examples

const a = 0;
a = 1;

const b = 0;
b += 1;

const c = 0;

Compliant Code Examples

const a = 0;

for (const a in [1, 2, 3]) { // `a` is re-defined (not modified) on each loop step.
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis