Convert var to let or const
var with block-scoped variables
const are block-scope variable declarations that can replace 'var' declarations in many cases.
const declares blocked-scoped variables that cannot be re-assigned.
let declares block-scoped variables that can be changed.
They are available since ES6 and are preferred over function-scope, modifiable
var declarations, because they make it easier to reason about the code.
When there are several variables declared in a statement, this refactoring does not change the declaration to prevent formatting breakages and linter issues.
What do I need to consider?
var declarations can define global variables visible in other files and script sections in some environments.
However, when you directly include scripts in the browser using the script tag (
var could define globals, and converting to
const could break your code.
- Code Assist ID (for the configuration file):
- You can configure custom keyboard shortcuts with these code action kinds:
- This code assist provides refactoring suggestions. Learn how to configure the refactoring suggestion visibility.