Disallow reassigning const variables

Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Metadata

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

Language: JavaScript

Severity: Error

Category: Best Practices

Description

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;
++c;

Compliant Code Examples

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

for (const a in [1, 2, 3]) { // `a` is re-defined (not modified) on each loop step.
    console.log(a);
}
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

PREVIEWING: alai97/reorganize-some-sections-in-dora-metrics