对象文字在控制台中表现得很奇怪 [英] Object literals behaves weird in the console
问题描述
在JavaScript控制台(我正在使用Chrome)中,表达式 {}
的计算结果为 undefined
。如果我执行 var a = {}
,则表达式 a
的计算结果为 Object {}
。为什么表达式 {}
的计算结果为 Object {}
(在控制台中)?
In the JavaScript console (I'm using Chrome), the expression {}
evaluates to undefined
. If I execute var a = {}
, the expression a
evaluates to Object {}
. Why doesn't the expression {}
evaluates to Object {}
(in the console)?
此外, {a:4}
似乎评估为 4
,表达式 {a:4,b:5}
显然是不正确的语法。
Further more, {a: 4}
seems to evaluate to 4
, and the expression {a: 4, b: 5}
is apparently incorrect syntax.
推荐答案
{}
被视为< a href =https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/block\"rel =nofollow>阻止而不是对象
块语句用于对零个或多个语句进行分组。
块由一对花括号分隔。
A block statement is used to group zero or more statements. The block is delimited by a pair of curly brackets.
这篇关于对象文字在控制台中表现得很奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!