Javascript Funky array mishap

后端 未结 5 1900
慢半拍i
慢半拍i 2020-12-06 00:09
function a() {
  var b = [\"b\"];
  console.log(b);
  //console.log(b.slice());
  b = b.push(\"bb\"); 
}
a();

In a \"perfect\" world you would thin

5条回答
  •  醉话见心
    2020-12-06 00:29

    This is a known problem with console.log.

    Instead of turning the parameter into a string when you call the method, the parameter is stored and turned into a string when it's displayed in the UI. As nothing happens in the UI while the function is running, you will see the state of the object as it is when you exit the function.

提交回复
热议问题