Strange behaviour of JavaScript in Chrome Developer Tool

邮差的信 提交于 2019-12-01 03:49:58

This is the way chrome evaluates your input:

with (typeof __commandLineAPI !== 'undefined' ? __commandLineAPI : { __proto__: null }) {
 // your code here...
}

So once your input is }{ it becomes

with (typeof __commandLineAPI !== 'undefined' ? __commandLineAPI : { __proto__: null }) {}{} // indefined

Next input }-+{ becomes

undefined -+ {} // NaN

And so on.

This happens because Chrome wraps the code you enter in the console in the following construction:

with (typeof __commandLineAPI !== 'undefined' ? __commandLineAPI : { __proto__: null }) {
  // Your code
}

So, when you enter something like } 10 {, the code evaluates to:

with (typeof __commandLineAPI !== 'undefined' ? __commandLineAPI : { __proto__: null }) {
  } 10 {
}

which is empty with block, a number, and empty structural block.

__commandLineAPI is the internal object that contains Chrome Command Line API.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!