What does the following code output and why? function foo() { return { bar: ‘baz’ }; } function foo2() { return { bar: ‘baz’ }; } console.log(foo(), foo2());

JavaScript Professional Hard

JavaScript Professional — Hard

What does the following code output and why? function foo() { return { bar: ‘baz’ }; } function foo2() { return { bar: ‘baz’ }; } console.log(foo(), foo2());

Key points

  • ASI automatically inserts semicolons in JavaScript
  • The missing semicolon in foo() does not affect the output
  • The missing semicolon in foo2() causes it to return undefined

Ready to go further?

Related questions