Page 140 - JavaScript
P. 140

if (...)
         {

         }

         function (a, b, ...)
         {

         }


        This has been adopted to avoid semicolon insertion in return statements that return objects:


         function foo()
         {
             return // A semicolon will be inserted here, making the function return nothing
             {
                 foo: 'foo'
             };
         }

         foo(); // undefined

         function properFoo() {
             return {
                 foo: 'foo'
             };
         }

         properFoo(); // { foo: 'foo' }


        In most languages the placement of the starting bracket is just a matter of personal preference, as
        it has no real impact on the execution of the code. In JavaScript, as you've seen, placing the initial
        bracket in the next line can lead to silent errors.


        Read Automatic Semicolon Insertion - ASI online:
        https://riptutorial.com/javascript/topic/4363/automatic-semicolon-insertion---asi




































        https://riptutorial.com/                                                                               97
   135   136   137   138   139   140   141   142   143   144   145