新的 Null 判断运算符??

新的 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;

  

猜你喜欢

转载自www.cnblogs.com/blogZhao/p/12561220.html