⭐ Reply with correct answer & Bonus points for explanation ⚡
💡 Correct answer with detailed explanation will be updated in comments after 48 hours.
Code -
function foo1() {
return {
bar: 'Hello'
}
}
function foo2() {
return
{
bar: 'World'
}
}
console.log(foo1());
console.log(foo2());
Top comments (1)
foo1
returns an object as expectedThe ASI (automatic semicolon insertion) in JS doing its job here actually causes a bug. The value being returned should begin on the same line, or else foo2 gets compiled down to this:
This can be fixed by telling JS to start at the next line after the return by using parens