Home >Web Front-end >JS Tutorial >What are the data types in TypeScript? (code example)

What are the data types in TypeScript? (code example)

藏色散人
藏色散人Original
2019-03-26 11:18:563271browse

Whenever a variable is created, the intention is to assign some value to the variable, but what type of value can be assigned to the variable depends on the data type of the variable. In typeScript, type System represents the different types of data types supported by typeScript. Data types are classified as follows:

What are the data types in TypeScript? (code example)

Built-in data types: TypeScript has some predefined data types-

Built-in data type Keyword Description
Number Number It is used to represent integers and floating point numbers
Boolean Boolean Represents true and false
String String It is used to represent a sequence of characters
Void Void Usually used for function return types
Null Null Use it when the object does not have any value
Undefined Undefined Indicates the value of an uninitialized variable
Any Any If you declare a variable using the Any data type, you can assign any type of value to the variable

Example:

let a: null = null;
let b: number = 123;

let c: number = 123.456;
let d: string = ‘Geeks’;
let e: undefined = undefined;
let f: boolean = true;
let g: number = 0b111001; // 二进制
let h: number = 0o436; // 八进制
let i: number = 0xadf0d; // Hexa-Decimal

User-defined data types: In addition to built-in data types, users can also customize data types. User-defined types include enums, classes, interfaces, arrays, and tuples.

Note: Among the built-in data types, any is a special data type and the super data type of all data types. If we declare a variable with any data type, then we can assign any type value to the variable.

Example:

let a: any = null;
let b: any =123;
let c: any = 123.456;
let d: any = ‘Geeks’;
let e: any = undefined;
let f: any = true;

Related recommendations: "typescript document tutorial"

This article is about the introduction of data types in TypeScript. I hope it will help you if you need Friends help!

The above is the detailed content of What are the data types in TypeScript? (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn