Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange behaviour of JavaScript in Chrome Developer Tool

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

I didn't find this behaviour in another browsers, just in Chrome.

Maybe it's a feature, but why and how it works, can it be problem with JavaScript engine?

like image 994
Alex Saskevich Avatar asked Jul 11 '15 16:07

Alex Saskevich


People also ask

Can I edit JavaScript in Chrome dev tools?

Use the Chrome DevTools Sources panel to: View files. Edit CSS and JavaScript. Create and save Snippets of JavaScript, which you can run on any page.

How do I stop JavaScript execution in Chrome?

Open Chrome DevTools. Press Control+Shift+P or Command+Shift+P (Mac) to open the Command Menu. Start typing javascript , select Disable JavaScript, and then press Enter to run the command. JavaScript is now disabled.


1 Answers

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.

like image 173
Vasili Molakhau Avatar answered Sep 22 '22 14:09

Vasili Molakhau