Uncaught SyntaxError: Unexpected token instanceof (with Chrome Javascript console)

bal*_*teo 6 javascript google-chrome-devtools

I am surprised that the following code when input into the Chrome js console:

{} instanceof Object
Run Code Online (Sandbox Code Playgroud)

results in this error message:

Uncaught SyntaxError: Unexpected token instanceof

Can anyone please tell me why that is and how to fix it?

Rob*_*obG 12

例如,语法是:

RelationalExpression instanceof ShiftExpression
Run Code Online (Sandbox Code Playgroud)

根据ECMA-262§11.8.

{语句开头的标点符号被视为块的开头,因此以下}关闭块并结束语句.

以下instanceof运算符是下一个语句的开头,但它不能在开头,因为它必须以RelationalExpression开头,因此解析器会出错.

你需要{}通过在语句的开头添加其他内容来强制被视为对象文字,例如

({}) instanceof Object
Run Code Online (Sandbox Code Playgroud)