s

?? 和 | | 容易被忽略的地方。

?? =》 空值合并运算符。 只会判断 null 和 undefined。 

 

| | =》 短路运算。 不仅会判断 null 和undefined, ‘’ 和0 也都会判断!!!

 

ex: 

const a = null(undefined) ?? 1 => a === 1 

const b = null(undefined)  || 1 => a === 1

const aa = ''(0) ?? 1  =>  a === '' or a===0

const bb ''(0)  || 1 =>  bb === 1

本文作者:努力不搬砖的iori

本文链接:https://www.cnblogs.com/Hijacku/p/16454172.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   努力不搬砖的iori  阅读(71)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.