Defining a JavaScript object in console

后端 未结 6 522
夕颜
夕颜 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 04:52

     { a: 1, b: 2 }
    

    is a code block, with two wrongly labelled variables.

    To create an object, surround the code block by parentheses, so that the braces are interpreted as object literals:

    ({ a: 1, b: 2 })
    

提交回复
热议问题