JavaScript runtime











up vote
0
down vote

favorite












All the blogs and videos I peruse about the JS runtime talk about the stack, heap, and queue. One thing none of those examples have explained are what happens to function declarations when they are passed by the runtime?



No source I've seen talks about function declarations being stored in memory or having any sort of flag to reference to go back to that point, after the function is initially invoked.



For example, consider the following blog: https://blog.sessionstack.com/how-does-javascript-actually-work-part-1-b0bacc073cf



This particular blog post explains the call stack, but does not explain what happens to the function declaration multiply(x, y). Is it in any way stored or referenced for a future invocation?



function multiply(x, y) {
return x * y;
}
function printSquare(x) {
var s = multiply(x, x);
console.log(s);
}
printSquare(5);









share|improve this question






















  • This long read might be helpful to you: V8 Internals: an illustrated primer It talks about the internals of V8's engine and how it works.
    – Amy
    Nov 21 at 18:58

















up vote
0
down vote

favorite












All the blogs and videos I peruse about the JS runtime talk about the stack, heap, and queue. One thing none of those examples have explained are what happens to function declarations when they are passed by the runtime?



No source I've seen talks about function declarations being stored in memory or having any sort of flag to reference to go back to that point, after the function is initially invoked.



For example, consider the following blog: https://blog.sessionstack.com/how-does-javascript-actually-work-part-1-b0bacc073cf



This particular blog post explains the call stack, but does not explain what happens to the function declaration multiply(x, y). Is it in any way stored or referenced for a future invocation?



function multiply(x, y) {
return x * y;
}
function printSquare(x) {
var s = multiply(x, x);
console.log(s);
}
printSquare(5);









share|improve this question






















  • This long read might be helpful to you: V8 Internals: an illustrated primer It talks about the internals of V8's engine and how it works.
    – Amy
    Nov 21 at 18:58















up vote
0
down vote

favorite









up vote
0
down vote

favorite











All the blogs and videos I peruse about the JS runtime talk about the stack, heap, and queue. One thing none of those examples have explained are what happens to function declarations when they are passed by the runtime?



No source I've seen talks about function declarations being stored in memory or having any sort of flag to reference to go back to that point, after the function is initially invoked.



For example, consider the following blog: https://blog.sessionstack.com/how-does-javascript-actually-work-part-1-b0bacc073cf



This particular blog post explains the call stack, but does not explain what happens to the function declaration multiply(x, y). Is it in any way stored or referenced for a future invocation?



function multiply(x, y) {
return x * y;
}
function printSquare(x) {
var s = multiply(x, x);
console.log(s);
}
printSquare(5);









share|improve this question













All the blogs and videos I peruse about the JS runtime talk about the stack, heap, and queue. One thing none of those examples have explained are what happens to function declarations when they are passed by the runtime?



No source I've seen talks about function declarations being stored in memory or having any sort of flag to reference to go back to that point, after the function is initially invoked.



For example, consider the following blog: https://blog.sessionstack.com/how-does-javascript-actually-work-part-1-b0bacc073cf



This particular blog post explains the call stack, but does not explain what happens to the function declaration multiply(x, y). Is it in any way stored or referenced for a future invocation?



function multiply(x, y) {
return x * y;
}
function printSquare(x) {
var s = multiply(x, x);
console.log(s);
}
printSquare(5);






javascript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 18:43









Joseppi

34




34












  • This long read might be helpful to you: V8 Internals: an illustrated primer It talks about the internals of V8's engine and how it works.
    – Amy
    Nov 21 at 18:58




















  • This long read might be helpful to you: V8 Internals: an illustrated primer It talks about the internals of V8's engine and how it works.
    – Amy
    Nov 21 at 18:58


















This long read might be helpful to you: V8 Internals: an illustrated primer It talks about the internals of V8's engine and how it works.
– Amy
Nov 21 at 18:58






This long read might be helpful to you: V8 Internals: an illustrated primer It talks about the internals of V8's engine and how it works.
– Amy
Nov 21 at 18:58














2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










The code is evaluated in two stages: at first it gets parsed and then evaluated. During parsing, so-called EnvironmentRecords are created. The spec says:




Each declarative Environment Record is associated with an ECMAScript program scope containing variable, constant,
let, class, module, import, and/or function declarations. A declarative Environment Record binds the set of identifiers
defined by the declarations contained within its scope.




During evaluation phases, identifiers are looked up in the current environment record.






share|improve this answer






























    up vote
    0
    down vote













    They are added to the global window object, just like global variables.






    function multiply(x, y) {
    return x * y;
    }
    function printSquare(x) {
    var s = multiply(x, x);
    console.log(s);
    }
    printSquare(5);

    console.log(window.multiply(2,2));








    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: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      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%2f53418666%2fjavascript-runtime%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote



      accepted










      The code is evaluated in two stages: at first it gets parsed and then evaluated. During parsing, so-called EnvironmentRecords are created. The spec says:




      Each declarative Environment Record is associated with an ECMAScript program scope containing variable, constant,
      let, class, module, import, and/or function declarations. A declarative Environment Record binds the set of identifiers
      defined by the declarations contained within its scope.




      During evaluation phases, identifiers are looked up in the current environment record.






      share|improve this answer



























        up vote
        0
        down vote



        accepted










        The code is evaluated in two stages: at first it gets parsed and then evaluated. During parsing, so-called EnvironmentRecords are created. The spec says:




        Each declarative Environment Record is associated with an ECMAScript program scope containing variable, constant,
        let, class, module, import, and/or function declarations. A declarative Environment Record binds the set of identifiers
        defined by the declarations contained within its scope.




        During evaluation phases, identifiers are looked up in the current environment record.






        share|improve this answer

























          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          The code is evaluated in two stages: at first it gets parsed and then evaluated. During parsing, so-called EnvironmentRecords are created. The spec says:




          Each declarative Environment Record is associated with an ECMAScript program scope containing variable, constant,
          let, class, module, import, and/or function declarations. A declarative Environment Record binds the set of identifiers
          defined by the declarations contained within its scope.




          During evaluation phases, identifiers are looked up in the current environment record.






          share|improve this answer














          The code is evaluated in two stages: at first it gets parsed and then evaluated. During parsing, so-called EnvironmentRecords are created. The spec says:




          Each declarative Environment Record is associated with an ECMAScript program scope containing variable, constant,
          let, class, module, import, and/or function declarations. A declarative Environment Record binds the set of identifiers
          defined by the declarations contained within its scope.




          During evaluation phases, identifiers are looked up in the current environment record.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 at 18:54









          Amy

          21.3k1773131




          21.3k1773131










          answered Nov 21 at 18:52









          Jonas Wilms

          53.6k42547




          53.6k42547
























              up vote
              0
              down vote













              They are added to the global window object, just like global variables.






              function multiply(x, y) {
              return x * y;
              }
              function printSquare(x) {
              var s = multiply(x, x);
              console.log(s);
              }
              printSquare(5);

              console.log(window.multiply(2,2));








              share|improve this answer

























                up vote
                0
                down vote













                They are added to the global window object, just like global variables.






                function multiply(x, y) {
                return x * y;
                }
                function printSquare(x) {
                var s = multiply(x, x);
                console.log(s);
                }
                printSquare(5);

                console.log(window.multiply(2,2));








                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  They are added to the global window object, just like global variables.






                  function multiply(x, y) {
                  return x * y;
                  }
                  function printSquare(x) {
                  var s = multiply(x, x);
                  console.log(s);
                  }
                  printSquare(5);

                  console.log(window.multiply(2,2));








                  share|improve this answer












                  They are added to the global window object, just like global variables.






                  function multiply(x, y) {
                  return x * y;
                  }
                  function printSquare(x) {
                  var s = multiply(x, x);
                  console.log(s);
                  }
                  printSquare(5);

                  console.log(window.multiply(2,2));








                  function multiply(x, y) {
                  return x * y;
                  }
                  function printSquare(x) {
                  var s = multiply(x, x);
                  console.log(s);
                  }
                  printSquare(5);

                  console.log(window.multiply(2,2));





                  function multiply(x, y) {
                  return x * y;
                  }
                  function printSquare(x) {
                  var s = multiply(x, x);
                  console.log(s);
                  }
                  printSquare(5);

                  console.log(window.multiply(2,2));






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 at 18:47









                  forgivenson

                  3,82011428




                  3,82011428






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418666%2fjavascript-runtime%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Berounka

                      Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

                      Sphinx de Gizeh