0
function foo() {
   return
   {
      foo: 'bar'
   }
}

function bar() {
   return {
      foo: 'bar'
   }
}

typeof foo() === typeof bar(); //why this is false

I didnt get why typeof foo() === typeof bar() returing false

intekhab
  • 1,566
  • 1
  • 13
  • 19

1 Answers1

3

Because of the line break after return, foo() is equivalent to

function foo() {
   return;
   //    ↑ note the semicolon
   {
      foo: 'bar'
   }
}

and is returning undefined.

On the other hand, bar() is returning an object.

NPE
  • 486,780
  • 108
  • 951
  • 1,012