var is function-scoped, can be redeclared, and is hoisted with the value undefined. That can cause surprising bugs, for example a loop variable still existing after the loop.
let is block-scoped (inside the nearest { }) and cannot be used before its declaration. It can be reassigned.
const is also block-scoped and cannot be reassigned.
Note that const protects the binding, not the contents. const list = []; list.push(1); is fine. Only list = [] is an error.
Modern advice: use const by default, use let when you need to reassign, and avoid var. This makes the code easier to reason about, because a reader knows a const never points to something new.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Note that const protects the binding, not the contents.
const list = []; list.push(1);is fine. Onlylist = []is an error.Modern advice: use const by default, use let when you need to reassign, and avoid var. This makes the code easier to reason about, because a reader knows a const never points to something new.