首页 > 其他 > 详细

新的 Null 判断运算符??

时间:2020-03-24 19:45:20      阅读:113      评论:0      收藏:0      [点我收藏+]

新的 Null 判断运算符?? 它的行为类似||

?? 只有运算符左侧的值为null或undefined时,才会返回右侧的值

||  es5除了 null或undefined ,空字符串或false或0,都会返回右侧的值 
const headerText = response.settings.headerText || ‘Hello, world!‘;
const animationDuration = response.settings.animationDuration || 300;
const showSplashScreen = response.settings.showSplashScreen || true;
const headerText = response.settings.headerText ?? ‘Hello, world!‘;
const animationDuration = response.settings.animationDuration ?? 300;
const showSplashScreen = response.settings.showSplashScreen ?? true;

  

 

新的 Null 判断运算符??

原文:https://www.cnblogs.com/blogZhao/p/12561220.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!