Strange JavaScript behavior in Chrome Developer Tool

Recently, working with JavaScript in the Developer Tool, I found a strange function. Chrome takes any code between the opening bracket with the operator (plus, minus sign) and the operator with closing brackets and executes it like this: enter image description here

I did not find this behavior in other browsers, only in Chrome.

Maybe this is a feature, but why and how it works, maybe there is a problem with the JavaScript engine?

+8
javascript google-chrome google-chrome-devtools v8
source share
2 answers

Here's how chrome rates your input:

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

So, as soon as your input }{ it becomes

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

Next entry }-+{ becomes

 undefined -+ {} // NaN 

And so on.

+7
source share

This is because Chrome wraps the code that 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 an empty with block, a number, and an empty structural block.

__commandLineAPI is an internal object that contains the Chrome command line API .

+4
source share

All Articles