Identifier 'head' is never reassigned; use 'const' instead of 'let'. Open
let head = document.getElementsByTagName('head')[0];
- Read upRead up
- Exclude checks
Rule: prefer-const
Requires that variable declarations use const
instead of let
and var
if possible.
If a variable is only assigned to once when it is declared, it should be declared using 'const'
Notes
- Has Fix
Config
An optional object containing the property "destructuring" with two possible values:
- "any" (default) - If any variable in destructuring can be const, this rule warns for those variables.
- "all" - Only warns if all variables in destructuring can be const.
Examples
"prefer-const": true
"prefer-const": true,[object Object]
Schema
{
"type": "object",
"properties": {
"destructuring": {
"type": "string",
"enum": [
"all",
"any"
]
}
}
}
For more information see this page.
Identifier 'analyticsMeta' is never reassigned; use 'const' instead of 'var'. Open
var analyticsMeta = document.createElement('meta');
- Read upRead up
- Exclude checks
Rule: prefer-const
Requires that variable declarations use const
instead of let
and var
if possible.
If a variable is only assigned to once when it is declared, it should be declared using 'const'
Notes
- Has Fix
Config
An optional object containing the property "destructuring" with two possible values:
- "any" (default) - If any variable in destructuring can be const, this rule warns for those variables.
- "all" - Only warns if all variables in destructuring can be const.
Examples
"prefer-const": true
"prefer-const": true,[object Object]
Schema
{
"type": "object",
"properties": {
"destructuring": {
"type": "string",
"enum": [
"all",
"any"
]
}
}
}
For more information see this page.
Forbidden 'var' keyword, use 'let' or 'const' instead Open
var analyticsMeta = document.createElement('meta');
- Read upRead up
- Exclude checks
Rule: no-var-keyword
Disallows usage of the var
keyword.
Use let
or const
instead.
Rationale
Declaring variables using var
has several edge case behaviors that make var
unsuitable for modern code.
Variables declared by var
have their parent function block as their scope, ignoring other control flow statements.
var
s have declaration "hoisting" (similar to function
s) and can appear to be used before declaration.
Variables declared by const
and let
instead have as their scope the block in which they are defined,
and are not allowed to used before declaration or be re-declared with another const
or let
.
Notes
- Has Fix
Config
Not configurable.
Examples
"no-var-keyword": true
For more information see this page.