0

I've heard that in JavaScript, primitive types are stored on the stack and that objects are stored on the heap. Is that true for all cases even for values inside of a function's execution scope? Moreover, are all globally scoped variables and functions stored on the global object (window in the browser) in JavaScript and is that considered to be the "heap" or part of the heap? Or are the primitive types themselves stored on the stack and reference types on the heap and then the identifiers are added as properties to the global objects and point to those values on the stack/heap?

2
  • 2
    The nice thing about a language like JavaScript is that for the vast majority of programming situations you don't have to worry about that at all. Commented Apr 17, 2020 at 16:35
  • @Pointy truly appreciate the response! :) Commented Apr 17, 2020 at 16:51

1 Answer 1

2

There is no heap and no stack. JavaScript's memory model is very abstract. How things end up in your computers memory is totally up to the engine. Given that modern engines perform a lot of optimizations, values might end up in different regions of the memory even in different optimization stages, so one really can't tell.

Sign up to request clarification or add additional context in comments.

1 Comment

I appreciate the response, Jonas! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.