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?
-
2The 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.Pointy– Pointy2020-04-17 16:35:34 +00:00Commented Apr 17, 2020 at 16:35
-
@Pointy truly appreciate the response! :)tychomag149– tychomag1492020-04-17 16:51:53 +00:00Commented Apr 17, 2020 at 16:51
Add a comment
|
1 Answer
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.
1 Comment
tychomag149
I appreciate the response, Jonas! :)