我有Javascript这个简单的问题,我想比较两个变量,但它不能正常工作。我甚至检查了变量的类型是相同的。请帮忙。 具体来说,我得到数字警报,我甚至得到当前计数器的警报是5总计是5,但我期望它进入“那么”。变量比较
function fun(idCount, finalCallback) {
this.idCount = parseInt(idCount);
var counter = 0;
var strings = {};
this.register = function(str, id) {
counter++;
strings[parseInt(id)] = str;
if(counter == this.idCount) {
alert("Going to override");
//blabla
} else {
alert("Current counter is: " + counter + " Total " + idCount + ". Types: " + typeof counter + " and " + typeof idCount);
}
}
}
请记住,包括radix参数为'parseInt':例如'parseInt(id,10)' –
因为无论如何它们都是数字,所以我相信我并不需要进行解析。但是怎么可能数字显然是相同的,但比较失败了呢? – Tib51