DEV Community

Discussion on: JavaScript Memes and Jokes ... Keep em coming 😁

Collapse
 
jamesbohacek profile image
James Bohacek

OK, I get the rest, but why the hell does {} + [] === 0

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

Welcome to JavaScript, LOL.

Collapse
 
shuvalov_js profile image
Senior JavaScript Artist Anton • Edited

{} + [] is the most stupid thing people joking about JS ever. Actually, the behavior is the same like for []+{} — it's calling toValue(), but in the CLI/browser console, when you're writing an expression starts from from {}, it actually means not an object, but a block, that means empty instructions set to compiler in this context. So the expression is just '+[]'.

Thread Thread
 
sharadcodes profile image
Sharad Raj (He/Him)

Some serious art stuff