Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{} + [] === 0 is false in nodejs but true in chrome #44781

Closed
himself65 opened this issue Sep 25, 2022 · 3 comments
Closed

{} + [] === 0 is false in nodejs but true in chrome #44781

himself65 opened this issue Sep 25, 2022 · 3 comments
Labels
v8 engine Issues and PRs related to the V8 dependency.

Comments

@himself65
Copy link
Member

himself65 commented Sep 25, 2022

Version

16.x, 18.x

Platform

Linux himself65 5.15.0-48-generic #54-Ubuntu SMP Fri Aug 26 13:26:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

What do you see instead?

image

@himself65 himself65 added the v8 engine Issues and PRs related to the V8 dependency. label Sep 25, 2022
@himself65
Copy link
Member Author

Maybe related to #44650?

@bnoordhuis
Copy link
Member

bnoordhuis commented Sep 25, 2022

The REPL evaluates it as ({} + [] === 0) - note the parens. It's the difference between these two:

> eval('{} + [] === 0')
true
> eval('({} + [] === 0)')
false

Without the parens, the {} is an empty block, not an object literal. Replace it with {1 + 2 + 3} and you get the same result. edit: I didn't make it clear but what is actually compared is +[] === 0, the {} is a red herring.

Not really a bug, just mildly unexpected behavior.

@himself65
Copy link
Member Author

Thanks for the correct!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

No branches or pull requests

2 participants