Some minutes ago, while playing with javascript, I noticed a strange behaviour of console.log()
. In fact it seems to log "distorted" variables. Take a look to the following:
var res = document.getElementById("res");
var arr = ["1", "2", "3"];
arr.push("4");
res.innerHTML = JSON.stringify(arr)+'<br>';
console.log(arr);
arr.push("5");
res.innerHTML += JSON.stringify(arr);
console.log(arr);
<div id="res"></div>
It prints correct variables into #res
but not into browser console (Firefox 37)
Could someone explain me why this happens?