0

** I have created two functions with different name & same properties and when I was checking surprisingly it's giving me different output. I don't understand what was is the problem exactly. I was expecting same result for both functions. See the below code**

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

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

console.log("foo1 returns:");
console.log(foo1());
console.log("foo2 returns:");
console.log(foo2());

Below is the Output:

foo1 returns:
Object {bar: "hello"}
foo2 returns:
undefined 
RamBhomkar
  • 91
  • 6

1 Answers1

3

It's because you have a new line after your return statement in the second function.

So instead of returning the object with bar, it just returns without a specified value, which returns undefined.

ultraGentle
  • 5,084
  • 1
  • 19
  • 45