JavaScript variables and constants
A variable gives a name to a value so your program can use it later.
What you will learn
- How to declare a value with
letorconst - When reassignment is allowed
Minimal example
let count = 0; count = count + 1; const siteName = 'Yugien';Use let when a variable needs a new value and const when the binding should not be reassigned.
Common mistakes
constprevents reassignment, but it does not make every object immutable.- Prefer
letandconstin new code instead ofvar.