In TypeScript, we can explicitly define the type of a variable as shown below:
let age: number = 5;
But in the above case, even without the explicity number
type, TypeScript can infer the type by the value assigned, which is 5
.
Observe the code below.
let age = 5;
age = "Five";
The second line throws an error because TypeScript already infered the type of age
as number
.
