0

I have an iife & a inner function.The inner function is returning an object in first case the { is immediately after the return keyword, in second case the brace { starts in a new line. In fist case the value is correctly returned and in second case it is throwing an undefined error

(function() {
  function sayHello() {
    var name = "myName";
    return {
      fullName: name
    }
  }
  console.log(sayHello().fullName);
})();

(function() {
  function sayHello() {
    var name = "myName";
    return 
    {
      fullName: name
    }
  }
  console.log(sayHello().fullName);
})();

I am not able to understand the effect statement in a new line after return statement & I am only guessing the return statement is getting terminated even though there is a statement in next line

brk
  • 48,835
  • 10
  • 56
  • 78
  • 3
    This is known as automatic semicolon insertion. – Alex Jun 01 '18 at 14:05
  • If it were me, i'd just remove ASI from javascript. It's not a whitespace oriented language and such a thing is just making more confusion and bugs. – ASDFGerte Jun 01 '18 at 14:07

0 Answers0