当前位置:网站首页>&& 与 ||
&& 与 ||
2022-06-10 17:50:00 【SeriousLose】
与(&&)
- 运算符将会返回第一个false/‘falsy’的值。当所有的操作数都是true时,将返回最后一个表达式的结果。
举个
let one = 1, two = 2, three = 3;
console.log(one && two && three); // Result: 3
console.log(0 && null); // Result: 0
或(||)
- 运算符将返回第一个true/‘truthy’的值。当所有的操作数都是false时,将返回最后一个表达式的结果。
举个
let one = 1, two = 2, three = 3;
console.log(one || two || three); // Result: 1
console.log(0 || null); // Result: null
function fn1(name,sex){
// 这句话用到了短路原理
var sex = sex || "男”; // 男
console.log(name+"的性别是"+sex);
}
fn1("lily”);
return (foo || []).length;
// 返回一个数组的长度
if(!name) {
initName()
}
<=>
name || initName()
// 假设后端返回的用户数据为 data
const data = {
name: 'xiaoer',
age: 18,
company: null
}
if (data.company && data.company.name) {
initCompany();
}
<=>
data.company && data.company.name && initCompany();
边栏推荐
- 三部曲套路解bob活命问题
- Faster Planner——Kinodynamic Astar详解
- Step on the pit. The BigDecimal was improperly used, resulting in P0 accident!
- 【技术分析】探讨大世界游戏的制作流程及技术——前期流程篇
- Abbexa 无细胞 DNA 试剂盒说明书
- Domestic cosmetics, lost 618
- 正斜杠“/”、反斜杠“\、”转义字符“\”、文件路径分割符傻傻记不清楚
- Abbexa丙烯酰胺-PEG-NHS说明书
- Abbexa 1,3-二棕榈素 CLIA 试剂盒解决方案
- makefile出问题:无法检测文件的更新
猜你喜欢

Research on next generation distributed file system

leecode27,977-双指针法

Container containing the most water

Win7系统下无法正常安装JLINK CDC UART驱动的问题解决

(CVPR 2020) RandLA-Net: Efficient Semantic Segmentation of Large-Scale Point Clouds

ADS,AXD基本使用说明

XML&Xpath解析

盛最多水得容器

Faster Planner——Kinodynamic Astar详解

XML & XPath parsing
随机推荐
【存储】下一代分布式文件系统 研究
Developers changing the world - Yao Guang teenagers playing Tetris
How to locate the hot problem of the game
【技术分析】探讨大世界游戏的制作流程及技术——前期流程篇
C language -- 14 loop statement for
IP summary (tcp/ip volumes 1 and 2)
Canvas fire burning H5 animation JS special effects
优惠券的工厂与策略模式实现方案
微信小程序仿陶票票课程设计
掌握高性能计算前,我们先了解一下它的历史
mysql备份和shell脚本手动执行没问题,crontab定时执行失败
数据的软删除—什么时候需要?又如何去实现?
C language -- 13 loop statement while
XML&Xpath解析
美学心得(第二百三十七集) 罗国正
AI 加持实时互动|ZegoAvatar 面部表情随动技术解析
聊聊远程办公那些事儿,参与征文领稿费拿大奖!
线性移动棋
c语言---9 初识宏、指针
“双碳”背景下 数据中心规划设计的新趋势及展望