9:40 Most of the primitive values are actually being stored in the heap. I feel like this statement is wrong. Correct me if I am wrong. But all the primitive values are stored in Stack. I asked chat GPT too for this. Here is what I found "Primitive Values (typically small): These are stored on the stack. These values include string, number, boolean, null, undefined, symbol, and bigint. They are usually stored directly on the stack because they are simple and fixed in size. Reference Values (larger and more complex): Objects, arrays, functions, and other non-primitive values are stored in the heap. The variable holds a reference to the location in the heap where the actual value is stored. Regarding the notion of "larger" primitive values being stored in the heap, in some JavaScript engines, there may be optimizations that handle large strings or other large primitive values differently. For instance, if a string is particularly large, the engine might store it in the heap to avoid stack overflow and manage memory more efficiently."
Perhaps unsurprisingly, ChatGPT's explanation is completely wrong, and seems made up rather than referencing anything remotely real. Primitives in objects are always stored on the heap, as are the objects themselves. The variable that reference the object might be on the stack, or it might be in a register. The stack isn't used as much in JavaScript bytecode as for instance in C, where all local variables are on the stack. JavaScript uses the stack for storing arguments, as well as local variables as part of the stack frame, but most of the time that variable is only a reference to somewhere on the heap. Meaning that every instance of say a floating point number like 3.14, will reference the same value on the heap, and not stored individually in each stack. Small integers (that can be stored as 32 bit signed int) are the exception, but most of the time they are stored and used in registers, even when passed along to other functions. Strings are NEVER stored on the stack, as they are - contrary to what ChatGPT says - NEVER fixed in size. Different engines might differ on how much or how little they use the stack, but most of the time, it only stores references to the heap.
Can you please share the additional material which was pointed out at the end of the session? Or even the corresponding slack channel would be super helpful!
Great explanation!🎉😊 ☝️ I wanted to point out that when you were using the term of "pointing" and "pointers" as an analogy, It might confuse people with the pointers that are managed by lower level langs as C and C++. This particular concept that she was referring to by "linking" some fragments of the code stored in the stack, to others in the heap, It's called "Reference", which is similar to "Pointers" but not exactly.
Thank you for the great presentation, I learned a lot !
This talk is awesome! Will be definitely looking for more by Kateryna
9:40 Most of the primitive values are actually being stored in the heap.
I feel like this statement is wrong. Correct me if I am wrong. But all the primitive values are stored in Stack.
I asked chat GPT too for this. Here is what I found
"Primitive Values (typically small): These are stored on the stack. These values include string, number, boolean, null, undefined, symbol, and bigint. They are usually stored directly on the stack because they are simple and fixed in size.
Reference Values (larger and more complex): Objects, arrays, functions, and other non-primitive values are stored in the heap. The variable holds a reference to the location in the heap where the actual value is stored.
Regarding the notion of "larger" primitive values being stored in the heap, in some JavaScript engines, there may be optimizations that handle large strings or other large primitive values differently. For instance, if a string is particularly large, the engine might store it in the heap to avoid stack overflow and manage memory more efficiently."
Perhaps unsurprisingly, ChatGPT's explanation is completely wrong, and seems made up rather than referencing anything remotely real.
Primitives in objects are always stored on the heap, as are the objects themselves. The variable that reference the object might be on the stack, or it might be in a register.
The stack isn't used as much in JavaScript bytecode as for instance in C, where all local variables are on the stack. JavaScript uses the stack for storing arguments, as well as local variables as part of the stack frame, but most of the time that variable is only a reference to somewhere on the heap. Meaning that every instance of say a floating point number like 3.14, will reference the same value on the heap, and not stored individually in each stack.
Small integers (that can be stored as 32 bit signed int) are the exception, but most of the time they are stored and used in registers, even when passed along to other functions.
Strings are NEVER stored on the stack, as they are - contrary to what ChatGPT says - NEVER fixed in size.
Different engines might differ on how much or how little they use the stack, but most of the time, it only stores references to the heap.
Can you please share the additional material which was pointed out at the end of the session? Or even the corresponding slack channel would be super helpful!
Did you find them?
Great explanation!🎉😊
☝️ I wanted to point out that when you were using the term of "pointing" and "pointers" as an analogy, It might confuse people with the pointers that are managed by lower level langs as C and C++. This particular concept that she was referring to by "linking" some fragments of the code stored in the stack, to others in the heap, It's called "Reference", which is similar to "Pointers" but not exactly.
amazing🤩
Awesome
var-👁-ible.