为什么我的三元 if 语句不计算 NULL?

Why doesn't my ternary if statement evaluate for NULL?

我正在尝试根据通过 Ajax 函数从数据库返回的值更改附加按钮的文本。

 .append($('<td>').attr('id', "tdBookingStatus" + i).html(val.HasCustomerArrived === true ? "Checked in" : (val.HasCustomerArrived == null) ? " ": "Cancelled"))

但它对 NULL 不起作用,即使函数返回 NULL 但它不起作用我尝试了 =====! 但没有任何效果。

如果您正在考虑该值,还需要检查 === ''。使用 null 是行不通的。

//for blank value
var test = '';
var res = test === true ? "Checked in" : (test === null || test === '') ? " ": "Cancelled"

console.log(res);

//for null value
var test = null;
var res = test === true ? "Checked in" : (test === null || test === '') ? " ": "Cancelled"

console.log(res);

//for true value
var test = true;
var res = test === true ? "Checked in" : (test === null || test === '') ? " ": "Cancelled"
console.log(res);

//for false value
var test = false;
var res = test === true ? "Checked in" : (test === null || test === '') ? " ": "Cancelled"
console.log(res);