Step 2 – Basic Data Types in TypeScript

TypeScript has a set of basic data types that can be used to define variables and constants. These data types are similar to those found in other programming languages, such as JavaScript. Here are the basic data types in TypeScript:

  1. Number: This data type is used to represent both integer and floating-point numbers. In TypeScript, numbers are represented using the number keyword. For example:
let count: number = 10;
let price: number = 9.99;

  1. String: This data type is used to represent text. In TypeScript, strings are represented using the string keyword. For example:
let message: string = "Hello, TypeScript!";

  1. Boolean: This data type is used to represent true/false values. In TypeScript, booleans are represented using the boolean keyword. For example:
let isCompleted: boolean = false;

  1. Null: This data type is used to represent the absence of any value. In TypeScript, null is represented using the null keyword. For example:
let result: null = null;

  1. Undefined: This data type is used to represent a variable that has not been assigned a value. In TypeScript, undefined is represented using the undefined keyword. For example:
let score: undefined = undefined;

  1. Any: This data type is used to represent any type of value. In TypeScript, any is represented using the any keyword. For example:
let value: any = "Hello";
value = 10;

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.