Defining a JavaScript object in console

后端 未结 6 526
夕颜
夕颜 2020-12-18 04:18

When I type simple objects to Chrome JavaScript Console, I get an output like this:

>true
true
>1/3
0.3333333333333333

And so on.

6条回答
  •  太阳男子
    2020-12-18 05:04

    It's because an opening { with no context is interpreted as the beginning of a block. You can use parentheses:

    ({ a: 1, b: 2 })
    

    As it is though, it's just a block of execution - like one might find after an if or for. So you can type:

    {alert("Hello!");}
    

    Here's more about that. Blocks sort of return values too, which is both awesome and disappointing.

提交回复
热议问题