【发布时间】:2018-05-01 01:53:00
【问题描述】:
如果调试显示变量为 0,那么我认为我应该能够使用 ==='0' 或 ===0 来捕获它,但这不起作用。我不得不只使用 == ,然后它就起作用了:
var offset = 0;
alert("## DEBUG non_sortable_columns " + non_sortable_columns)
if (non_sortable_columns == '0' || non_sortable_columns == 0) {
offset = 1;
}
我第一次尝试,但没有成功:
var offset = 0;
alert("## DEBUG non_sortable_columns " + non_sortable_columns)
if (non_sortable_columns === '0' || non_sortable_columns === 0) {
offset = 1;
}
值为 [0],[0] === [0] 为假。怎么可能是假的?
【问题讨论】:
-
console.log(non_sortable_columns, typeof non_sortable_columns)的输出是什么 -
我敢打赌是
false -
String
+值非常容易误导,总是console.log值本身而不涉及字符串连接。 -
首先,如果你想捕捉 '0' 或 0 那么 == 是比这种方法更自然的方法。
-
@gurvinder372
[0]
标签: javascript types