Function without parentheses returns a weird output

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite
1












Just asking to understand how it works:






function say(something) 
return something;

let name = `Reza`;

console.log(say `My name is`, name, '!');





It returns a very weird output. I think that My name is is a string within an array and everything else is just a string (correct me if I am wrong).



My Question is, what is the point of that and when would it make sense to use a function like that?



Also I would be glad if someone could tell me why My name is $name is not working (name returns as an empty string).



PS: I know that could use the function with parentheses and it would work but that's not my question.










share|improve this question

























    up vote
    6
    down vote

    favorite
    1












    Just asking to understand how it works:






    function say(something) 
    return something;

    let name = `Reza`;

    console.log(say `My name is`, name, '!');





    It returns a very weird output. I think that My name is is a string within an array and everything else is just a string (correct me if I am wrong).



    My Question is, what is the point of that and when would it make sense to use a function like that?



    Also I would be glad if someone could tell me why My name is $name is not working (name returns as an empty string).



    PS: I know that could use the function with parentheses and it would work but that's not my question.










    share|improve this question























      up vote
      6
      down vote

      favorite
      1









      up vote
      6
      down vote

      favorite
      1






      1





      Just asking to understand how it works:






      function say(something) 
      return something;

      let name = `Reza`;

      console.log(say `My name is`, name, '!');





      It returns a very weird output. I think that My name is is a string within an array and everything else is just a string (correct me if I am wrong).



      My Question is, what is the point of that and when would it make sense to use a function like that?



      Also I would be glad if someone could tell me why My name is $name is not working (name returns as an empty string).



      PS: I know that could use the function with parentheses and it would work but that's not my question.










      share|improve this question













      Just asking to understand how it works:






      function say(something) 
      return something;

      let name = `Reza`;

      console.log(say `My name is`, name, '!');





      It returns a very weird output. I think that My name is is a string within an array and everything else is just a string (correct me if I am wrong).



      My Question is, what is the point of that and when would it make sense to use a function like that?



      Also I would be glad if someone could tell me why My name is $name is not working (name returns as an empty string).



      PS: I know that could use the function with parentheses and it would work but that's not my question.






      function say(something) 
      return something;

      let name = `Reza`;

      console.log(say `My name is`, name, '!');





      function say(something) 
      return something;

      let name = `Reza`;

      console.log(say `My name is`, name, '!');






      javascript






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 6 hours ago









      Reza Saadati

      383113




      383113






















          5 Answers
          5






          active

          oldest

          votes

















          up vote
          3
          down vote














          why My name is $name is not working (name returns as an empty
          string).




          This is because you have to pull out the value of name from the array of string values and return it



          Try this:






          function say(something) 
          var str0 = something[0]
          return str0;

          let name = `Reza`;
          console.log(say`My name is$name`, name, '!'); // My name is Reza !





          We will receive thing like this:



          enter image description here



          This is the result after running your codes on the Chrome devtools:



          enter image description here



          Let's see how we can explain what is actually going on. Well then, what you're using is called Tagged templates:




          A more advanced form of template literals are tagged templates. Tags allow you to parse template literals with a function. The first argument of a tag function contains an array of string values.




          That's why we see an array in the result:



          For instance, if we run this codes on Chrome devtools:



          function say(something) 
          return something;

          console.log(say`anything`);


          On the console tab, we will receive this result:



          enter image description here



          For more information, you could read it here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates



          As we can see, the weird raw property, according to MDN - Raw strings, it is:




          The special raw property, available on the first function argument of tagged templates, allows you to access the raw strings as they were entered, without processing escape sequences.




          For example:



          function tag(strings) 
          console.log(strings.raw[0]);


          tag`string text line 1 n string text line 2`;
          // logs "string text line 1 n string text line 2" ,
          // including the two characters '' and 'n'


          And you are using the console.log() method, according to MDN-Console.log() we have its signature:



          Syntax: Console.log()




          console.log(obj1 [, obj2, ..., objN]);



          console.log(msg [, subst1, ..., substN]);




          Parameters



          'obj1 ... objN'




          A list of JavaScript objects to output. The string representations of
          each of these objects are appended together in the order listed and
          output.




          msg




          A JavaScript string containing zero or more substitution strings.




          subst1 ... substN




          JavaScript objects with which to replace substitution strings within
          msg. This gives you additional control over the format of the output.




          In your case, you're passing multiple arguments into the Console.log() method, hence it will work as the document said here: Outputting multiple objects



          enter image description here






          share|improve this answer





























            up vote
            1
            down vote













            say tag is missing the arguments to the placeholders in the template string:






            function shout(parts, name/*<--HERE*/) 
            return `$parts[0]$name$parts[1]!!!`;


            let name = `Reza`;
            console.log(shout `My name is $name`);





            say receives data from the template string as a split string around the placeholders:



            [
            "My name is ",
            "!"
            ] Reza


            Look at this example from the MDN Documentation:



            function myTag(strings, personExp, ageExp) 
            var str0 = strings[0]; // "That "
            var str1 = strings[1]; // " is a "

            var ageStr;
            if (ageExp > 99)
            ageStr = 'centenarian';
            else
            ageStr = 'youngster';


            // We can even return a string built using a template literal
            return `$str0$personExp$str1$ageStr`;


            var person = 'Mike';
            var age = 28;
            var output = myTag`That $ person is a $ age `;





            share|improve this answer





























              up vote
              0
              down vote













              Doing My name is $name should work. Its because your passing My name is to the say function as a tagged template literal, which by default passes the arguments as an array



              https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals






              share|improve this answer



























                up vote
                0
                down vote













                Your tagged template has a missing argument, it should include a strings array argument as first argument.



                 function say(strings, something) 
                return strings[0] + "Mr. " + something +"!";


                let name = `Reza`;
                console.log(say `My name is $name`);





                share|improve this answer



























                  up vote
                  0
                  down vote













                  Make it simple






                  console.log `Hi there`;






                  why My name is $name is not working (name returns as an empty string).




                  console.log(say `My name is`, name, '!'); /* I don't see `$name` here */


                  Also, name was never passed as an argument to say function!






                  function say(something) 
                  return something;

                  let name = `Reza`;
                  /* say without () */
                  console.log(say `My name is $name !`);

                  /* say with () */
                  console.log(say(`My name is $name !`));








                  let who = 'everyone';
                  console.log `Hello $who`; /* note, no -> () */
                  console.log(`Hello $who`);








                  share|improve this answer






















                    Your Answer





                    StackExchange.ifUsing("editor", function ()
                    StackExchange.using("externalEditor", function ()
                    StackExchange.using("snippets", function ()
                    StackExchange.snippets.init();
                    );
                    );
                    , "code-snippets");

                    StackExchange.ready(function()
                    var channelOptions =
                    tags: "".split(" "),
                    id: "1"
                    ;
                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

                    StackExchange.using("externalEditor", function()
                    // Have to fire editor after snippets, if snippets enabled
                    if (StackExchange.settings.snippets.snippetsEnabled)
                    StackExchange.using("snippets", function()
                    createEditor();
                    );

                    else
                    createEditor();

                    );

                    function createEditor()
                    StackExchange.prepareEditor(
                    heartbeatType: 'answer',
                    convertImagesToLinks: true,
                    noModals: false,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: 10,
                    bindNavPrevention: true,
                    postfix: "",
                    onDemand: true,
                    discardSelector: ".discard-answer"
                    ,immediatelyShowMarkdownHelp:true
                    );



                    );













                     

                    draft saved


                    draft discarded


















                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52573941%2ffunction-without-parentheses-returns-a-weird-output%23new-answer', 'question_page');

                    );

                    Post as a guest






























                    5 Answers
                    5






                    active

                    oldest

                    votes








                    5 Answers
                    5






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes








                    up vote
                    3
                    down vote














                    why My name is $name is not working (name returns as an empty
                    string).




                    This is because you have to pull out the value of name from the array of string values and return it



                    Try this:






                    function say(something) 
                    var str0 = something[0]
                    return str0;

                    let name = `Reza`;
                    console.log(say`My name is$name`, name, '!'); // My name is Reza !





                    We will receive thing like this:



                    enter image description here



                    This is the result after running your codes on the Chrome devtools:



                    enter image description here



                    Let's see how we can explain what is actually going on. Well then, what you're using is called Tagged templates:




                    A more advanced form of template literals are tagged templates. Tags allow you to parse template literals with a function. The first argument of a tag function contains an array of string values.




                    That's why we see an array in the result:



                    For instance, if we run this codes on Chrome devtools:



                    function say(something) 
                    return something;

                    console.log(say`anything`);


                    On the console tab, we will receive this result:



                    enter image description here



                    For more information, you could read it here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates



                    As we can see, the weird raw property, according to MDN - Raw strings, it is:




                    The special raw property, available on the first function argument of tagged templates, allows you to access the raw strings as they were entered, without processing escape sequences.




                    For example:



                    function tag(strings) 
                    console.log(strings.raw[0]);


                    tag`string text line 1 n string text line 2`;
                    // logs "string text line 1 n string text line 2" ,
                    // including the two characters '' and 'n'


                    And you are using the console.log() method, according to MDN-Console.log() we have its signature:



                    Syntax: Console.log()




                    console.log(obj1 [, obj2, ..., objN]);



                    console.log(msg [, subst1, ..., substN]);




                    Parameters



                    'obj1 ... objN'




                    A list of JavaScript objects to output. The string representations of
                    each of these objects are appended together in the order listed and
                    output.




                    msg




                    A JavaScript string containing zero or more substitution strings.




                    subst1 ... substN




                    JavaScript objects with which to replace substitution strings within
                    msg. This gives you additional control over the format of the output.




                    In your case, you're passing multiple arguments into the Console.log() method, hence it will work as the document said here: Outputting multiple objects



                    enter image description here






                    share|improve this answer


























                      up vote
                      3
                      down vote














                      why My name is $name is not working (name returns as an empty
                      string).




                      This is because you have to pull out the value of name from the array of string values and return it



                      Try this:






                      function say(something) 
                      var str0 = something[0]
                      return str0;

                      let name = `Reza`;
                      console.log(say`My name is$name`, name, '!'); // My name is Reza !





                      We will receive thing like this:



                      enter image description here



                      This is the result after running your codes on the Chrome devtools:



                      enter image description here



                      Let's see how we can explain what is actually going on. Well then, what you're using is called Tagged templates:




                      A more advanced form of template literals are tagged templates. Tags allow you to parse template literals with a function. The first argument of a tag function contains an array of string values.




                      That's why we see an array in the result:



                      For instance, if we run this codes on Chrome devtools:



                      function say(something) 
                      return something;

                      console.log(say`anything`);


                      On the console tab, we will receive this result:



                      enter image description here



                      For more information, you could read it here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates



                      As we can see, the weird raw property, according to MDN - Raw strings, it is:




                      The special raw property, available on the first function argument of tagged templates, allows you to access the raw strings as they were entered, without processing escape sequences.




                      For example:



                      function tag(strings) 
                      console.log(strings.raw[0]);


                      tag`string text line 1 n string text line 2`;
                      // logs "string text line 1 n string text line 2" ,
                      // including the two characters '' and 'n'


                      And you are using the console.log() method, according to MDN-Console.log() we have its signature:



                      Syntax: Console.log()




                      console.log(obj1 [, obj2, ..., objN]);



                      console.log(msg [, subst1, ..., substN]);




                      Parameters



                      'obj1 ... objN'




                      A list of JavaScript objects to output. The string representations of
                      each of these objects are appended together in the order listed and
                      output.




                      msg




                      A JavaScript string containing zero or more substitution strings.




                      subst1 ... substN




                      JavaScript objects with which to replace substitution strings within
                      msg. This gives you additional control over the format of the output.




                      In your case, you're passing multiple arguments into the Console.log() method, hence it will work as the document said here: Outputting multiple objects



                      enter image description here






                      share|improve this answer
























                        up vote
                        3
                        down vote










                        up vote
                        3
                        down vote










                        why My name is $name is not working (name returns as an empty
                        string).




                        This is because you have to pull out the value of name from the array of string values and return it



                        Try this:






                        function say(something) 
                        var str0 = something[0]
                        return str0;

                        let name = `Reza`;
                        console.log(say`My name is$name`, name, '!'); // My name is Reza !





                        We will receive thing like this:



                        enter image description here



                        This is the result after running your codes on the Chrome devtools:



                        enter image description here



                        Let's see how we can explain what is actually going on. Well then, what you're using is called Tagged templates:




                        A more advanced form of template literals are tagged templates. Tags allow you to parse template literals with a function. The first argument of a tag function contains an array of string values.




                        That's why we see an array in the result:



                        For instance, if we run this codes on Chrome devtools:



                        function say(something) 
                        return something;

                        console.log(say`anything`);


                        On the console tab, we will receive this result:



                        enter image description here



                        For more information, you could read it here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates



                        As we can see, the weird raw property, according to MDN - Raw strings, it is:




                        The special raw property, available on the first function argument of tagged templates, allows you to access the raw strings as they were entered, without processing escape sequences.




                        For example:



                        function tag(strings) 
                        console.log(strings.raw[0]);


                        tag`string text line 1 n string text line 2`;
                        // logs "string text line 1 n string text line 2" ,
                        // including the two characters '' and 'n'


                        And you are using the console.log() method, according to MDN-Console.log() we have its signature:



                        Syntax: Console.log()




                        console.log(obj1 [, obj2, ..., objN]);



                        console.log(msg [, subst1, ..., substN]);




                        Parameters



                        'obj1 ... objN'




                        A list of JavaScript objects to output. The string representations of
                        each of these objects are appended together in the order listed and
                        output.




                        msg




                        A JavaScript string containing zero or more substitution strings.




                        subst1 ... substN




                        JavaScript objects with which to replace substitution strings within
                        msg. This gives you additional control over the format of the output.




                        In your case, you're passing multiple arguments into the Console.log() method, hence it will work as the document said here: Outputting multiple objects



                        enter image description here






                        share|improve this answer















                        why My name is $name is not working (name returns as an empty
                        string).




                        This is because you have to pull out the value of name from the array of string values and return it



                        Try this:






                        function say(something) 
                        var str0 = something[0]
                        return str0;

                        let name = `Reza`;
                        console.log(say`My name is$name`, name, '!'); // My name is Reza !





                        We will receive thing like this:



                        enter image description here



                        This is the result after running your codes on the Chrome devtools:



                        enter image description here



                        Let's see how we can explain what is actually going on. Well then, what you're using is called Tagged templates:




                        A more advanced form of template literals are tagged templates. Tags allow you to parse template literals with a function. The first argument of a tag function contains an array of string values.




                        That's why we see an array in the result:



                        For instance, if we run this codes on Chrome devtools:



                        function say(something) 
                        return something;

                        console.log(say`anything`);


                        On the console tab, we will receive this result:



                        enter image description here



                        For more information, you could read it here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates



                        As we can see, the weird raw property, according to MDN - Raw strings, it is:




                        The special raw property, available on the first function argument of tagged templates, allows you to access the raw strings as they were entered, without processing escape sequences.




                        For example:



                        function tag(strings) 
                        console.log(strings.raw[0]);


                        tag`string text line 1 n string text line 2`;
                        // logs "string text line 1 n string text line 2" ,
                        // including the two characters '' and 'n'


                        And you are using the console.log() method, according to MDN-Console.log() we have its signature:



                        Syntax: Console.log()




                        console.log(obj1 [, obj2, ..., objN]);



                        console.log(msg [, subst1, ..., substN]);




                        Parameters



                        'obj1 ... objN'




                        A list of JavaScript objects to output. The string representations of
                        each of these objects are appended together in the order listed and
                        output.




                        msg




                        A JavaScript string containing zero or more substitution strings.




                        subst1 ... substN




                        JavaScript objects with which to replace substitution strings within
                        msg. This gives you additional control over the format of the output.




                        In your case, you're passing multiple arguments into the Console.log() method, hence it will work as the document said here: Outputting multiple objects



                        enter image description here






                        function say(something) 
                        var str0 = something[0]
                        return str0;

                        let name = `Reza`;
                        console.log(say`My name is$name`, name, '!'); // My name is Reza !





                        function say(something) 
                        var str0 = something[0]
                        return str0;

                        let name = `Reza`;
                        console.log(say`My name is$name`, name, '!'); // My name is Reza !






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited 4 hours ago

























                        answered 6 hours ago









                        Nguyễn Thanh Tú

                        1,258114




                        1,258114






















                            up vote
                            1
                            down vote













                            say tag is missing the arguments to the placeholders in the template string:






                            function shout(parts, name/*<--HERE*/) 
                            return `$parts[0]$name$parts[1]!!!`;


                            let name = `Reza`;
                            console.log(shout `My name is $name`);





                            say receives data from the template string as a split string around the placeholders:



                            [
                            "My name is ",
                            "!"
                            ] Reza


                            Look at this example from the MDN Documentation:



                            function myTag(strings, personExp, ageExp) 
                            var str0 = strings[0]; // "That "
                            var str1 = strings[1]; // " is a "

                            var ageStr;
                            if (ageExp > 99)
                            ageStr = 'centenarian';
                            else
                            ageStr = 'youngster';


                            // We can even return a string built using a template literal
                            return `$str0$personExp$str1$ageStr`;


                            var person = 'Mike';
                            var age = 28;
                            var output = myTag`That $ person is a $ age `;





                            share|improve this answer


























                              up vote
                              1
                              down vote













                              say tag is missing the arguments to the placeholders in the template string:






                              function shout(parts, name/*<--HERE*/) 
                              return `$parts[0]$name$parts[1]!!!`;


                              let name = `Reza`;
                              console.log(shout `My name is $name`);





                              say receives data from the template string as a split string around the placeholders:



                              [
                              "My name is ",
                              "!"
                              ] Reza


                              Look at this example from the MDN Documentation:



                              function myTag(strings, personExp, ageExp) 
                              var str0 = strings[0]; // "That "
                              var str1 = strings[1]; // " is a "

                              var ageStr;
                              if (ageExp > 99)
                              ageStr = 'centenarian';
                              else
                              ageStr = 'youngster';


                              // We can even return a string built using a template literal
                              return `$str0$personExp$str1$ageStr`;


                              var person = 'Mike';
                              var age = 28;
                              var output = myTag`That $ person is a $ age `;





                              share|improve this answer
























                                up vote
                                1
                                down vote










                                up vote
                                1
                                down vote









                                say tag is missing the arguments to the placeholders in the template string:






                                function shout(parts, name/*<--HERE*/) 
                                return `$parts[0]$name$parts[1]!!!`;


                                let name = `Reza`;
                                console.log(shout `My name is $name`);





                                say receives data from the template string as a split string around the placeholders:



                                [
                                "My name is ",
                                "!"
                                ] Reza


                                Look at this example from the MDN Documentation:



                                function myTag(strings, personExp, ageExp) 
                                var str0 = strings[0]; // "That "
                                var str1 = strings[1]; // " is a "

                                var ageStr;
                                if (ageExp > 99)
                                ageStr = 'centenarian';
                                else
                                ageStr = 'youngster';


                                // We can even return a string built using a template literal
                                return `$str0$personExp$str1$ageStr`;


                                var person = 'Mike';
                                var age = 28;
                                var output = myTag`That $ person is a $ age `;





                                share|improve this answer














                                say tag is missing the arguments to the placeholders in the template string:






                                function shout(parts, name/*<--HERE*/) 
                                return `$parts[0]$name$parts[1]!!!`;


                                let name = `Reza`;
                                console.log(shout `My name is $name`);





                                say receives data from the template string as a split string around the placeholders:



                                [
                                "My name is ",
                                "!"
                                ] Reza


                                Look at this example from the MDN Documentation:



                                function myTag(strings, personExp, ageExp) 
                                var str0 = strings[0]; // "That "
                                var str1 = strings[1]; // " is a "

                                var ageStr;
                                if (ageExp > 99)
                                ageStr = 'centenarian';
                                else
                                ageStr = 'youngster';


                                // We can even return a string built using a template literal
                                return `$str0$personExp$str1$ageStr`;


                                var person = 'Mike';
                                var age = 28;
                                var output = myTag`That $ person is a $ age `;





                                function shout(parts, name/*<--HERE*/) 
                                return `$parts[0]$name$parts[1]!!!`;


                                let name = `Reza`;
                                console.log(shout `My name is $name`);





                                function shout(parts, name/*<--HERE*/) 
                                return `$parts[0]$name$parts[1]!!!`;


                                let name = `Reza`;
                                console.log(shout `My name is $name`);






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited 6 hours ago

























                                answered 6 hours ago









                                Rafael

                                3,30751432




                                3,30751432




















                                    up vote
                                    0
                                    down vote













                                    Doing My name is $name should work. Its because your passing My name is to the say function as a tagged template literal, which by default passes the arguments as an array



                                    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals






                                    share|improve this answer
























                                      up vote
                                      0
                                      down vote













                                      Doing My name is $name should work. Its because your passing My name is to the say function as a tagged template literal, which by default passes the arguments as an array



                                      https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals






                                      share|improve this answer






















                                        up vote
                                        0
                                        down vote










                                        up vote
                                        0
                                        down vote









                                        Doing My name is $name should work. Its because your passing My name is to the say function as a tagged template literal, which by default passes the arguments as an array



                                        https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals






                                        share|improve this answer












                                        Doing My name is $name should work. Its because your passing My name is to the say function as a tagged template literal, which by default passes the arguments as an array



                                        https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered 6 hours ago









                                        jman93

                                        616




                                        616




















                                            up vote
                                            0
                                            down vote













                                            Your tagged template has a missing argument, it should include a strings array argument as first argument.



                                             function say(strings, something) 
                                            return strings[0] + "Mr. " + something +"!";


                                            let name = `Reza`;
                                            console.log(say `My name is $name`);





                                            share|improve this answer
























                                              up vote
                                              0
                                              down vote













                                              Your tagged template has a missing argument, it should include a strings array argument as first argument.



                                               function say(strings, something) 
                                              return strings[0] + "Mr. " + something +"!";


                                              let name = `Reza`;
                                              console.log(say `My name is $name`);





                                              share|improve this answer






















                                                up vote
                                                0
                                                down vote










                                                up vote
                                                0
                                                down vote









                                                Your tagged template has a missing argument, it should include a strings array argument as first argument.



                                                 function say(strings, something) 
                                                return strings[0] + "Mr. " + something +"!";


                                                let name = `Reza`;
                                                console.log(say `My name is $name`);





                                                share|improve this answer












                                                Your tagged template has a missing argument, it should include a strings array argument as first argument.



                                                 function say(strings, something) 
                                                return strings[0] + "Mr. " + something +"!";


                                                let name = `Reza`;
                                                console.log(say `My name is $name`);






                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered 5 hours ago









                                                Calvin

                                                593




                                                593




















                                                    up vote
                                                    0
                                                    down vote













                                                    Make it simple






                                                    console.log `Hi there`;






                                                    why My name is $name is not working (name returns as an empty string).




                                                    console.log(say `My name is`, name, '!'); /* I don't see `$name` here */


                                                    Also, name was never passed as an argument to say function!






                                                    function say(something) 
                                                    return something;

                                                    let name = `Reza`;
                                                    /* say without () */
                                                    console.log(say `My name is $name !`);

                                                    /* say with () */
                                                    console.log(say(`My name is $name !`));








                                                    let who = 'everyone';
                                                    console.log `Hello $who`; /* note, no -> () */
                                                    console.log(`Hello $who`);








                                                    share|improve this answer


























                                                      up vote
                                                      0
                                                      down vote













                                                      Make it simple






                                                      console.log `Hi there`;






                                                      why My name is $name is not working (name returns as an empty string).




                                                      console.log(say `My name is`, name, '!'); /* I don't see `$name` here */


                                                      Also, name was never passed as an argument to say function!






                                                      function say(something) 
                                                      return something;

                                                      let name = `Reza`;
                                                      /* say without () */
                                                      console.log(say `My name is $name !`);

                                                      /* say with () */
                                                      console.log(say(`My name is $name !`));








                                                      let who = 'everyone';
                                                      console.log `Hello $who`; /* note, no -> () */
                                                      console.log(`Hello $who`);








                                                      share|improve this answer
























                                                        up vote
                                                        0
                                                        down vote










                                                        up vote
                                                        0
                                                        down vote









                                                        Make it simple






                                                        console.log `Hi there`;






                                                        why My name is $name is not working (name returns as an empty string).




                                                        console.log(say `My name is`, name, '!'); /* I don't see `$name` here */


                                                        Also, name was never passed as an argument to say function!






                                                        function say(something) 
                                                        return something;

                                                        let name = `Reza`;
                                                        /* say without () */
                                                        console.log(say `My name is $name !`);

                                                        /* say with () */
                                                        console.log(say(`My name is $name !`));








                                                        let who = 'everyone';
                                                        console.log `Hello $who`; /* note, no -> () */
                                                        console.log(`Hello $who`);








                                                        share|improve this answer














                                                        Make it simple






                                                        console.log `Hi there`;






                                                        why My name is $name is not working (name returns as an empty string).




                                                        console.log(say `My name is`, name, '!'); /* I don't see `$name` here */


                                                        Also, name was never passed as an argument to say function!






                                                        function say(something) 
                                                        return something;

                                                        let name = `Reza`;
                                                        /* say without () */
                                                        console.log(say `My name is $name !`);

                                                        /* say with () */
                                                        console.log(say(`My name is $name !`));








                                                        let who = 'everyone';
                                                        console.log `Hello $who`; /* note, no -> () */
                                                        console.log(`Hello $who`);








                                                        console.log `Hi there`;





                                                        console.log `Hi there`;





                                                        function say(something) 
                                                        return something;

                                                        let name = `Reza`;
                                                        /* say without () */
                                                        console.log(say `My name is $name !`);

                                                        /* say with () */
                                                        console.log(say(`My name is $name !`));





                                                        function say(something) 
                                                        return something;

                                                        let name = `Reza`;
                                                        /* say without () */
                                                        console.log(say `My name is $name !`);

                                                        /* say with () */
                                                        console.log(say(`My name is $name !`));





                                                        let who = 'everyone';
                                                        console.log `Hello $who`; /* note, no -> () */
                                                        console.log(`Hello $who`);





                                                        let who = 'everyone';
                                                        console.log `Hello $who`; /* note, no -> () */
                                                        console.log(`Hello $who`);






                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited 5 hours ago

























                                                        answered 5 hours ago









                                                        Arvind

                                                        15.5k11531




                                                        15.5k11531



























                                                             

                                                            draft saved


                                                            draft discarded















































                                                             


                                                            draft saved


                                                            draft discarded














                                                            StackExchange.ready(
                                                            function ()
                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52573941%2ffunction-without-parentheses-returns-a-weird-output%23new-answer', 'question_page');

                                                            );

                                                            Post as a guest













































































                                                            Comments

                                                            Popular posts from this blog

                                                            What does second last employer means? [closed]

                                                            List of Gilmore Girls characters

                                                            Confectionery