TypeScript Lecture of basic data types used ----

Foreword

TypeScript developed by Microsoft's free and open source programming language.

TypeScript design goal is to develop large-scale applications, it can be compiled into pure JavaScript, the JavaScript compiler can run on any browser.

TypeScript is a superset of JavaScript, support for ECMAScript 6 standard.

Know on the line, it is recommended before learning TypeScript, go to understand and learn JavaScript, because after js learn, easier to use ts.

 ts basic data types:

ts in order to make the code written in more standardized, more conducive to the maintenance, increase the types of verification. (Js more than the norm)

Ts in, there are the following several types of data:

 

Boolean (boolean)

Digital type (number)

String type (string)

Array type (array)

Tuple type (tuple)

Enumerated types (enum)

Of any type (any)

null 和 undefined

void type

never type

Note that, in addition check the type of ts

Boolean (boolean)

Ts must specify the type of code to write:

Such as: the definition of variables, and let var reputation

var variable name: boolean = true / false;

 

var flag: boolean = true;

 

Digital type (number):

var variable name: number = 123;

 

var num: Number = 123 ; 
Surely = 345;
console.log (whether);

 

String type (string): string type must be enclosed in double quotes

var variable name: string = "abc";

 

var str: string = "abc";
str = "bcd"
console.log( str );

 

数组类型(array):ts中定义数组有两种方式

第一种方式:

var arr:number[] = [ 11, 22, 33 ]

 

 

 

 

 

第二种方式:

var arr:Array<number> = [ 11, 22, 33 ]

 

元组类型(tuple):元组类型属于数组的一种,给数组中每个位置指定一个类型

 

let arr:[number,string] = [123, "this is ts"]

 

枚举类型(enum):

enum 枚举名{

  标识符[=整形常数],

  标识符[=整形常数]

  ...

  标识符[=整形常数]

};

 

enum Flag {
    success = 1,
    error = 2
}
let s: Flag.success;
console.log( s ) 

//用单词替代数字,比如一些状态码,使用枚举通俗易懂

 

enum Color{
    blue,
    red,
    orange
}
let s: Color.red;
console.log( s ) 
//如果标识符没有赋值,则打印下标

 

 

 

Guess you like

Origin www.cnblogs.com/mqflive81/p/11427396.html