??
双问号语法
概念是 当左边的值为 null 或者 undefined 时,就返回右边的值
console.log(undefined??1); //1
console.log(null??1);//1
console.log(NaN??1);//NaN
console.log(true??1);//true
console.log(false??1);//false
console.log(0??1);//0
console.log(-0??1);//-0
console.log('0'??1);//'0'
网友评论