Published onSeptember 10, 2026
Variables are one of the most basic building blocks of any TypeScript program. They allow you to store information such as names, numbers, user data, and application settings. If you're familiar with JavaScript, you'll find TypeScript variables very familiar, but TypeScript gives you an extra layer of type safety.
How to Declare Variables in TypeScript
TypeScript uses the same let, const, and var keywords as JavaScript. However, you can specify the expected data type using a colon (:).
For example:
Here,
must contain a string,
must contain a number, and
must contain a boolean value. If you accidentally assign the wrong type, TypeScript can warn you before the application runs.
Using
and
In modern TypeScript development,
and
are generally preferred over
.
Use
when the value needs to change:
Use
when the value should not be reassigned:
No Comment.