+ 1
JavaScript Code Explanation
var a = null; var b = {}; var c = a || b; alert(c); The answer of this challenge question is [Object Object] but how?
4 Respostas
+ 2
That's just what is displayed when you alert() any object
https://www.freecodecamp.org/news/object-object-in-javascript-meaning-in-js/#:~:text=What%20Happens%20If%20You%20Alert%20an%20Object%20in%20JavaScript%3F&text=From%20the%20image%20above%2C%20instead,get%20the%20string%20format%20displayed.
+ 2
The way I understand it is:
when you perform the above comparison "a || b" it is coercing "null" and "{}" into booleans. when coerced, null evaluates as false and objects as true. so "{}" wins the comparison battle and becomes the value set to var c.
+ 2
The answer is [Object Object] twice
But I don't know why?
+ 2
Thanks Aaron