Course Banner


Typescript Data Types

The Any type

There are data types like string, number etc. But  there is also a data type called ‘Any’ in typescript and that any data type is the super type of all types in TypeScript.When we define data type as any , we tell transpiler to make the variable independent of type checking.

Built-in types

The following table illustrates all the built-in types in TypeScript −

Data type

Keyword

Description

Number

number

Double precision 64-bit floating point values. It can be used to represent both, integers and fractions.

String

string

Represents a sequence of Unicode characters

Boolean

boolean

Represents logical values, true and false

Void

void

Used on function return types to represent non-returning functions

Null

null

Represents an intentional absence of an object value.

Undefined

undefined

Denotes value given to all uninitialized variables

Note − There is no integer type in TypeScript and JavaScript.

Null and undefined ─ Are they the same?

One of the most confusing data types of TypeScript and javascript is Null and Undefined. The null and undefined we can use  as values to a variable.

So, are null and Undefined same? No, both are not same.

When a  variable is  initialized with undefined that means the variable has no value or object assigned to it. On the other hand,  null means that the variable has been set to an object whose value is undefined.

User-defined  Data Types

Apart from built in types there are few user-defined types also.  And these are include Enumerations (enums), classes, interfaces, arrays, and tuple.




Ad Image