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);
javascript
add a comment |
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);
javascript
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
add a comment |
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);
javascript
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
javascript
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
add a comment |
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
add a comment |
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.
add a comment |
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));
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Nov 21 at 18:54
Amy
21.3k1773131
21.3k1773131
answered Nov 21 at 18:52
Jonas Wilms
53.6k42547
53.6k42547
add a comment |
add a comment |
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));
add a comment |
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));
add a comment |
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));
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));
answered Nov 21 at 18:47
forgivenson
3,82011428
3,82011428
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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