为什么以下计算结果为 true?
if(false, true) {
console.log("this is true");
}
输出为
this is true
,eslint 表示 Unexpected use of comma operator
通过检查,
false, true
似乎是 JavaScript 中的有效语句:
false, true;
console.log("meh");
假值包括假、零、空、空、未定义或 Nan,其他所有值(包括有效语句)均为真值。 因此,我们可以得出结论,您的
false, true
语句中的 if
条件评估为 true,这就是 print 语句发生的原因。