網站首頁 編程語言 正文
首先我們要了解 false,null,undefined,空字符串 即 “”,0,?NaN 都會被判為空
&&? ”與 “,兩邊條件都為true時,結果才為true
let a = 0;
let b = 1;
let c = a && '666'; //返回0
let d = b && '666'; //返回666
//&&左側是true則返回右側數據,是false返回左側
||? ”或 “,兩邊條件有一個為true時,結果就為true
let a = 0;
let b = 1;
let c = a || '666'; //返回0
let d = b || '666'; //返回666
//||左側是true則返回左側數據,是false返回右側
? :??”三目運算符“,等同于if(){}else{}
let a = 0;
let b = 1;
let c = a ? '666' : '777'; //返回'777'
let d = b ? '666' : '777'; //返回'666'
if(a){
let c = '666'
}else{
let c = '777'
}
//三目運算符可以代替簡單的if else
????”空值合并操作符“,當左側的操作數為?null
?或者?undefined
?時,返回其右側操作數,否則返回左側操作數
let a = null;
let b = undefined?;
let c = a ?? '666'; //返回'666'
let d = b ?? '666'; //返回'666'
let e = 0 ?? '666'; //返回 0
//當左側的操作數為?null?或者?undefined?時,返回其右側操作數,否則返回左側操作數
?.??”可選鏈操作符“,允許讀取位于連接對象鏈深處的屬性的值,而不必明確驗證鏈中的每個引用是否有效。在引用?null
?或者?undefined
?的情況下不會引起錯誤
let a = { b:'666'};
let c = a.b; //返回'666'
let d = a.c; //返回 undefined
let e = a.c.e; //報錯
let f = a?.c?.e; //返回 undefined
//允許讀取位于連接對象鏈深處的屬性的值,而不必明確驗證鏈中的每個引用是否有效。在引用?null?或者?undefined?的情況下不會引起錯誤
原文鏈接:https://blog.csdn.net/sugerinaflat/article/details/119272698
相關推薦
- 2022-09-08 Go語言中的Struct結構體_Golang
- 2022-08-03 Python?解析獲取?URL?參數及使用步驟_python
- 2022-12-14 C#中委托和事件的區別詳解_C#教程
- 2022-02-10 微信小程序this.triggerEvent(),父組件中使用子組件的事件
- 2022-09-22 Laravel解決高并發問題的思路
- 2022-12-01 docker?容器網絡模式詳解_docker
- 2022-06-24 Python統計序列和文件中元素的頻度_python
- 2022-07-13 解決 Webpack TypeError: cli.isMultipleCompiler is no
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支