{}+{} incosistency

Alan Schmitt alan.schmitt at polytechnique.org
Fri Apr 15 06:34:50 UTC 2016


On 2016-04-13 19:53, Vic99999 <vic99999 at yandex.ru> writes:

> if "{}+{}" is a statement, than how can it return (or yield) a result?

It returns a completion record, like every other construction
(http://www.ecma-international.org/ecma-262/6.0/#sec-completion-record-specification-type).
In most cases you don't get to see the value inside, but you can get to
it through eval.

In fact, I often use eval when I don't know if a console is running my
code as an expression or as a statement, as eval runs code as programs.
Running eval("{}+{}") and eval("({}+{})") nicely shows the two correct
results, which boils down to whether {} is a block
(http://www.ecma-international.org/ecma-262/6.0/#sec-block) with a
single empty statement, or if it's an object literal.

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-03, Mauna Loa Obs.): 404.83
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160415/60d14282/attachment.sig>


More information about the es-discuss mailing list