Course curriculum
Values, const and let
Choose between const and let, distinguish strings from numbers and compare values predictably.
About 9 minutes · BeginnerChoose a declaration
Use const when a binding will not be reassigned. Use let when you intend to assign it a new value. Clear names make each value’s purpose visible.
const does not make an object deeply immutable: properties can still change. It prevents replacing the binding itself.
const totalLessons = 5;
let completedLessons = 1;
completedLessons += 1;
console.log(totalLessons - completedLessons);3
Avoid accidental string joining
The + operator joins strings when a string operand is involved. Number converts a numeric string for arithmetic; invalid numeric text produces NaN.
Use Number.isFinite after conversion when input must be a usable finite number. Empty strings convert to zero, so validate required input separately.
console.log("12" + 3);
console.log(Number("12") + 3);
console.log(Number.isFinite(Number("twelve")));123 15 false
Use strict comparisons
=== compares without converting the two values to a common type. It makes a string and a number with similar spelling remain distinct.
Template literals use backticks and ${...} placeholders to combine values with explanatory text.
const score = 42;
console.log(score === "42");
console.log(`Score: ${score}`);false Score: 42
Try it yourself
Declare a unit price of 25 and a quantity of 3. Print “Total: 75” using a template literal.
Show a possible solution
const price = 25;
const quantity = 3;
console.log(`Total: ${price * quantity}`);Keep exploring: official JavaScript documentation.