js中使用两个问号

阅读 36

2022-03-23

const response = {
  settings: {
    nullValue: null,
    height: 800,
    carNum: 0,
    headerText: '',
    showSplashScreen: false
  }
};
const undefinedValue = response.settings.undefinedValue ?? 'some other default'; // result: 'some other default'
const headerText = response.settings.headerText ?? 'Hello, world!'; // result: ''
const animationDuration = response.settings.carNum?? 300; // result: 0
const showSplashScreen = response.settings.showSplashScreen ?? true; // result: false

精彩评论(0)

0 0 举报