为什么 {} + {} 在 Chrome 控制台中不再是 NaN? [英] Why is {} + {} no longer NaN in Chrome console?
问题描述
我今天注意到,当您在控制台中键入 {}+{}
时,Chrome 49 不再输出 NaN
.相反,它输出字符串 [object Object][object Object]
.
I noticed today that Chrome 49 no longer outputs NaN
when you type {}+{}
into the console. Instead it outputs the string [object Object][object Object]
.
这是为什么?语言有变化吗?
Why is this? Did the language change?
推荐答案
Chrome devtools 现在会自动将所有以 {
开头并以 }
结尾的内容包含在一对隐式的括号(见代码),强制其评估作为表达式.这样,{}
现在创建一个空对象.如果你回顾历史(↑),你可以看到这一点,前一行将包含在(…)
中.
Chrome devtools now automatically wrap everything that begins with {
and ends with }
in an implicit pair of parentheses (see code), to force its evaluation as an expression. That way, {}
creates an empty object now. You can see this if you go back through the history (↑), the previous line will be contained in (…)
.
为什么?我不知道,但是我猜它可以减少不了解块与对象字面量的新手的混淆,如果您只想评估一个表达.
Why? I don't know, but I could guess it reduces confusion for newbies that don't know of the block-vs-object-literal thing, and it's also more helpful if you just want to evaluate an expression.
事实上,这就是推理,如bug 499864一>.纯粹的方便.并且因为 node REPL 也有它(见代码).
And in fact that's the reasoning, as discussed in bug 499864. Pure convenience. And because node REPL had it as well (see code).
这篇关于为什么 {} + {} 在 Chrome 控制台中不再是 NaN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!