1.ts变量声明:
let num: number = 2
2.类型断言: 值 as 类型 (最简单的 let num: number = '1' as string, 但是请不要这样使用,使用类型断言,一般a是b子集,或者b是a子集)
3.变量作用域: 全局作用域,类作用域,局部作用域
const num = 12
class Number {
num_val = 13;
static sval = 10
storeNum():void{
const local_num = 14
}
}
4.ts运算符:
1.算数运算符: (+ - * / % ++ --) 类似js
2.关系运算符: ( == != > < >= <=)
3.逻辑运算符: ( && || !)
4.短路运算符: (&& ||)
5.位运算符: (用处少)
6.赋值运算符: ( = += -= *= /=)
7.三元运算符: (true? exprt1: export2)
8.类型运算符: typeof instanceof
9.负号运算符: (-)
10.字符串运算符: (+)
5.条件语句:
if else switch
6.循环语句: (for, for in, for of, forEach, every, some, set, map, while, do while) break语句 continue 语句
break语句和continue 语句区别: break 立即终止循环跳出,continue 立即跳出当前循环中的代码, 强迫开始下一次循环
7.函数: function functionName(): volid {}
带参数的函数: function functionName (param: number, param1: number):number {}
可选参数: function functionName (firstName: string, secondName?: string) {} let result = functionName('Bob')
默认参数: function functionName (param: number, param1: number = 2) =>{}
剩余参数: function fuctionName (firstName: string, ...restName: string[])=>{} functionName('Bob', 'tim', 'mark')
构造函数: new Function(a,b,()=>{})
const myFunction = new Function ('a','b', 'return a * b') myFunction(4,3)
递归函数
箭头函数
8.Number const newNumber = new Number('11111') Number 上存在很多方法
toFixed()
toLocaleString()
toPrecision()
toString()
valueOf()
9.String const str = new String('123456') 拥有length属性
charAt()
charCodeAt()
concat()
indexOf()
lastIndexOf()
'This is string one and again string'.lastIndexOf('string')
match()
str.match(/ain/g)
replace()
search()
slice()
split()
substr()
substring()
toLowerCase()
toUpperCase()
toString()
valueOf()