3.TypeScript Data Types - Tutorial Rays
TypeScript

3.TypeScript Data Types

3.TypeScript Data Types

As mentioned in the previous chapter,Javascript is a loosely Typed language because we don't define data type. But that does not mean javascript does not have data type.In fact javascript also have data typed. In TypeScript also, there is data types. But the difference between Javascript data types and TypeScript is that Javascript types are typecasting internally. On the other hand in TypeScript, we can define data type and we have to adhere to that data types. Though defining data type is optional also. TypeScript provides data types as a part of its optional Type System. The data type classification is as given below − 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.

Leave a Reply

Your email address will not be published. Required fields are marked *