In modern JavaScript, let vs const?
Options
- They are identical in every way in JavaScript
constcannot be reassigned;letcan be (Correct option)constobjects cannot be modified in any wayletcreates a global variable in all cases
Answer
const cannot be reassigned; let can. Both are block-scoped
Why
const total = 5; means the variable total cannot point to another value later. let count = 0; count = 1; is allowed.
Both exist only inside the { } block where they are declared.
Careful: const does not freeze objects. const user = {}; user.name = "Ana"; works; only user = other is forbidden.
Rule of thumb: use const by default, let when you must reassign, and avoid var.
Remember
const by default, let when it changes, never var.