Explicit Variable Declaration in Typescript
I am a Frontend React Developer ๐ฅฐ๐ฅฐ
A touch of goodness, Next.js and Typescript
I am passionate about Blockchain Development and Technologies ๐๐๐๐
Explicit Variable Declaration is a type of variable declaration where the developer explicitly let's Typescript know the variable datatype without utilizing the automatic Typescript datatype inference.
This is particularly useful for both the compiler and but especially for other developers working on the same project. They can easily know what a variable is all about by glancing across the codebase.
let name: string; // Explicit Variable Declaration
name = 'Joseph'; // Assigning "Joseph" to name
let isRunning: boolean;
isRunning = false;
let age: number = 30;
let about: string | number; // Union Types
about = 'Funny';
about = 40;
Note:
Union Types is a way to assign various datatypes to a variable in Typescript. In the above example, we let Typescript know that the about variable can contain both string and number datatypes


