Values and types
Variables with let and const
Goal: Declare variables and print values · 7 min
console.log(...) prints values — in the browser's developer console or in Node.js.
Declare variables with **const (cannot be reassigned) or let** (can be reassigned). Prefer const by default; use let only if the value must change. The old var has confusing scoping rules — avoid it in new code.
Statements usually end with a semicolon. Comments: // one line or /* several lines */. Names are case-sensitive and typically written in camelCase: userName, totalPrice.
Worked example: let vs const
countchanges, so it uses let.maxnever changes, so it uses const.- Output:
2 10
let count = 1;
const max = 10;
count = count + 1;
console.log(count, max);Output:
2 10