var
is globally scoped and hoisted, which can lead to unintended side effects. let
is block-scoped and can never be redeclared within that scope – much harder to break, but need to be careful about passing it to where it's needed and aware that it is still hoisted, albeit with no value (not even null). const
works similarly to let, but you cannot update the value (though you can update internal values).
- Source
- Link to Original 🔗
- Published
- Categories
- JavaScript
- Tags
- const, let, var, variables, JavaScript, scope
Explore Other Notes
⬅ Newer
The React cheatsheet for 2020
A very hand overview of the core concepts in React, from JSX to fragments to hooks. Includes quick reference to the core hooks and how/when to use them e.g. useState, useContext, useMemo …
Older ➡
Images good to the last byte
An exhaustive guide to image optimisation, compression, formats, and quality on the …
- <!DOCTYPE html> <html> <head> <title></title> </head> <body> <p>var is globally scoped and hoisted, which can lead to unintended side effects. let is block-scoped and can never be redeclared within that scope – much harder to break, but need to be careful about …</p> </body> </html>
- Murray Champernowne