I’m really a beginner in Javascript, and trying what i read as much as I can.
But when comes to pop() and push(), I get some strange results that I’m wondering about.
Here’s the code :
var arr = [];
arr.push(2,3);
console.log(arr);
console.log(arr.pop());
console.log(arr);
the result is :
[2, undefined × 1]
3
[2]
Shouldn’t it be :
[2, 3]
3
[2]
This is due to
console.log‘s asynchronous evaluation on your browser. By the time the result of the firstconsole.loghas been displayed, the item is already gone because ofpop().For accurate results, call
toString():