While going around reading a bit about JavaScript coercion, I came a across this.
[] + {}; // [object Object]
{} + []; // 0
I understand how this works but what I am not able to understand is why does "console.log"ging the above two statements and executing them in REPL results in two different things.
When ran in REPL mode
When ran in browser(Chrome, Firefox)
console.log([] + {}); // '[object Object]'
console.log({} + []); // '[object Object]'
My initial thought was maybe toString
being called on the console.log parameters, but that is definitely not the case. Any ideas?