Questions about the cast of js empty object types in Chrome

when an empty object is summed with another data, such as

{} + []
The empty object in front of

is generally treated as an empty block of code and becomes

+ [] // 0

so when empty objects and empty objects are summed

{} + {}

an empty object is treated as a code block is equal to

+ {}

the result should be NaN.

but in Chrome

{} + {} // "[object Object][object Object]"

obviously the first empty object is not treated as a code block.

in other browsers such as Firefox or IE

{} + {} 

the results are all NaN.

I don"t quite understand why it is different in

Chrome.

Apr.20,2022

because {} + {} has different parsing methods

  1.    {
       }
       +{}

    is preceded by an empty code block

  2. is parsed as an object before and after, and finally, the respective toString methods are called to concatenate strings
  3. .

to avoid the above ambiguity, you can use ({} + {}) to achieve consistency

.
Menu