Good practices to declare variables
General rule: Prefer non-reassignable, local scope, variables
- 1. Use by default const if possible
- 2. Use let if you need to re-assigned the variable
- 3. Avoid var (outdated, too large scope)
-
- Use only if you really need function scope
Rem.
- - const and let introduced in EC6
- - Many internet code still use the outdated var from previous JS