3

If I type

}{

in the console of Firefox or Chrome, the result is undefined, not a SyntaxError.

This construction return undefined (construction like }!{ return false). What is the reason for such behavior?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
smrnk
  • 58
  • 4
  • I partially updated your question - would be a good idea to clarify what the latter part of your question means. (interesting observation, don't know the answer) – AD7six Aug 18 '12 at 21:33
  • Yeah, but what does Internet Explorer say? – Waleed Khan Aug 18 '12 at 21:34
  • Possible duplicate: *[Why does this JavaScript code print "undefined" on the console?](https://stackoverflow.com/questions/10263190/why-does-this-javascript-code-print-undefined-on-the-console)* – Peter Mortensen Oct 20 '20 at 17:15

1 Answers1

7

When you enter debugger; in the console, a break point shows up, which reveals the answer:

with ((window && window.console && window.console._commandLineAPI) || {}) {
debugger;
}

In Chrome's developer tools, the input is wrapped inside a with block, then literally evaluated. So, when you put in }{, the following is evaluated:

with ((window && window.console && window.console._commandLineAPI) || {}) {
}{
}

This is an empty with block, followed by an empty block.

Exercise to reader: Try }for(;;){

Rob W
  • 341,306
  • 83
  • 791
  • 678