3 ms·
Hmm I cannot reproduce most of these. In node 19, the first two work okay, but the latter two do not agree: > [] + [] '' > [] + {} '[object Obj
by aftbit 4y ago
Hmm I cannot reproduce most of these. In node 19, the first two work okay, but the latter two do not agree:
> [] + []
''
> [] + {}
'[object Object]'
> {} + []
'[object Object]'
(expected: 0)
> {} + {}
'[object Object][object Object]'
(expected: NaN)
Furthermore, the Ruby one fails for me too, in irb 1.4.2, ruby 3.0.5p211:
irb(main):002:0> def method_missing(*args); args.join(" "); end
(irb):2: warning: redefining Object#method_missing may cause infinite loop
/usr/bin/irb: machine stack overflow in critical region (fatal)
- crdrost 4y agoYes! JavaScript is even more watty than you wat! Your context is implicitly parenthesizing the expressions you are evaluated, treating them as expressions rather than statements. Statements are also expressions of a sort too in JavaScript so uh there's also that. Here's the full wat matrix: > do {[] + []} while (false); '' > do {[] + {}} while (false); '[object Object]' > do {{} + []} while (false); 0 > do {{} + {}} while (false); NaN > do {([] + [])} while (false); '' > do {([] + {})} while (false); '[object Object]' > do {({} + [])} while (false); '[object Object]' > do {({} + {})} while (false); '[object Object][object Object]' (as a hint, `{} + []` is actually `{}; +[]`, that is not an addition operator in that context).
- runarberg 4y agoYeah, Gary was actually wrong about that one, you can actually hear objections from the audience: 1. [] + {} is actually the string '[object Object]' not an object per say, {} is the object and [] + casts it to string. 2. {} + [] depends on runtimes. In firefox the first {} is actually an empty statement, not an object Object.fromEntries([]) + [] is always the string "[Object object]" just like [] + {}. In node you can do this {} {} + [] or even {1 + 1} + [] for the desired 0. Effectively it is the same as +[] 3. {} + {} is the same. The first {} is an empty statement
- kaba0 4y agoSee sibling comment