?.语句
Typescript中?.相当于&&,可用于简化判空语句
a?.b相当与a&&a.b?a.b:undefined
![](https://img.haomeiwen.com/i26021157/d539b28b2a0c2850.png)
??语句
Typescript中的??相当于||
不同的是,在||中当左侧取值为false时会取右侧的值;但在??中当左侧取值不为null和undefined时,都去左侧的值
![](https://img.haomeiwen.com/i26021157/ff0c6a5abdb9edb1.png)
?语句
Typescript的?代表可选参数
在函数定义时,传入的参数为可传可不传时,可用该符号来说明
![](https://img.haomeiwen.com/i26021157/76fa969b89dac40f.png)
![](https://img.haomeiwen.com/i26021157/b997ae0c3f533a71.png)
!语句
Typescript的!使null和undefined类型可以赋值给其他类型并通过编译,表示该变量值可空
![](https://img.haomeiwen.com/i26021157/f554e1977dca6e78.png)
![](https://img.haomeiwen.com/i26021157/43f1ac3b80e2fab3.png)
![](https://img.haomeiwen.com/i26021157/c7c96e6c6cb91bdb.png)
![](https://img.haomeiwen.com/i26021157/02965628d70ff083.png)
网友评论