Pit caused by js return

Execute the following code:

function foo1()
{
  return {
      bar: "hello"
  };
}

function foo2()
{
  return
  {
      bar: "hello"
  };
}
console.log(foo1());
console.log(foo2());

The result is shocking, foo2 actually returns undfined, the reason is that there is no code after return, which is equivalent to return;

Guess you like

Origin blog.csdn.net/weixin_44494811/article/details/108769304