When I type simple objects to Chrome JavaScript Console, I get an output like this:
>true
true
>1/3
0.3333333333333333
And so on.
But a syntax error occurs when I type objects:
>{ a: 1, b: 2 }
SyntaxError: Unexpected token :
arguments: Array[1]
0: ":"
length: 1
__proto__: Array[0]
get message: function getter() { [native code] }
get stack: function getter() { [native code] }
set message: function setter() { [native code] }
set stack: function setter() { [native code] }
type: "unexpected_token"
__proto__: Error
While I know for sure that this expression could be correctly used in initializing an object, because:
>obj = { a: 1, b: 2 }
Object
a: 1
b: 2
__proto__: Object
Maybe it's a silly question, but I really want to know the reason why is this happening?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…