Can you clarify how JavaScript handles storage for primitive types and objects? Are primitive types always stored on the stack and objects on the heap, even within the scope of a function's execution? Also, are globally scoped variables and functions stored on the global object (such as 'window' in the browser), is this considered part of the heap? Or do primitive types reside on the stack and reference types on the heap, with identifiers pointing to values on the stack/heap stored as properties on global objects?