joews
joews

Reputation: 30340

void in Chrome console - strange SyntaxError: Unexpected token }

Purely a curiosity, but why does Chrome (31) raise SyntaxError: Unexpected token } when executing the (invalid) statement void from the JS console?

I understand that the JS engine should raise a syntax error - void requires an argument. I don't understand what a } has to do with it.

The same invalid statement, when executed from the URL bar with javascript:void or in a web page, results in a more sensible SyntaxError: Unexpected end of input.

Upvotes: 0

Views: 739

Answers (1)

apsillers
apsillers

Reputation: 116030

If you run a debugger; statement in the console, you'll see:

enter image description here

Your code is wrapped inside of with(console ...) block. The unexpected } is the one that closes the block. Mentally replace the debugger; with a void with no arguments, and you can see how you'd get that error.

Upvotes: 4

Related Questions