Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

Timeline for How do JavaScript closures work?

Current License: CC BY-SA 3.0

10 events
when toggle format what by license comment
Nov 24, 2023 at 18:55 comment added Yusuf you make sense and storing closured variables, even primitive ones, on heap will serve its purpose. but only closured ones are stored on heap or all variables ? that i could not find exact reference anywhere, atleast for v8 ?
Nov 24, 2023 at 10:53 comment added srgstm How variables are actually stored is implementation detail of the execution engine. You just shouldn't mentally picture them stored on the stack to get the understanding on how this really works. This is because captured variables (even primitive ones!) cannot be stored on the stack frame because when the function exits its stack frame is destroyed, but local variables (primitive or not) that get captured must live past that moment. It is of course possible for optimal performance that variables that aren't being captured be created on the stack.
Nov 8, 2023 at 18:01 comment added Yusuf No one has said this but you might be correct. Also, it must be understood that local variables in JavaScript are created not on the stack frame, but on the heap and destroyed only when no one is referencing them So I am just telling that I heard primitive data types stored on stack and non-primitive on heap, do you mean all are stored on heap and stack is never used for any variables ? Just asking
May 5, 2016 at 16:04 history edited Peter Mortensen CC BY-SA 3.0
Copy edited.
Dec 23, 2015 at 6:08 history edited srgstm CC BY-SA 3.0
added 109 characters in body
Feb 9, 2014 at 9:55 history edited srgstm CC BY-SA 3.0
added an example
Jun 6, 2013 at 10:22 history made wiki Post Made Community Wiki by Max Tkachenko
Nov 23, 2012 at 10:30 history edited srgstm CC BY-SA 3.0
added 508 characters in body
Nov 23, 2012 at 10:22 history edited srgstm CC BY-SA 3.0
added 508 characters in body
Oct 25, 2012 at 18:12 history answered srgstm CC BY-SA 3.0