我有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