Tsallaka zuwa abun ciki
Justice Tech School

Variables: let and const

Prefer const, use let when a value changes and avoid var. TypeScript infers the type from the first value, so annotations are often optional.

Example
const name = "Ada";
let age = 21;
age = 22;
console.log(name, age);
// age = "x"; // error: string is not assignable to number

Result

Ada 22

Exercise

Constant keyword.

 pi = 3.14;

Quiz Test

Which keyword is preferred when a value never changes?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.