If I declare var number1 = new Number(6);
will javascript use both heap and stack to store it in the memory. Is it possible to convert this number1 object to primitive type like
var number1 = 6;
if so, then will this action delete the reference of the object from heap, and will there be an impact on memory?
Asked
Active
Viewed 52 times
0
![](../../users/profiles/12816049.webp)
Lord
- 2,830
- 10
- 17
-
JavaScript doesn't really have the distinction between stack and heap allocation. – Barmar Apr 21 '20 at 21:29
-
Boxing is unrelated to stack versus heap. – Barmar Apr 21 '20 at 21:30
-
Well, I got pretty confused, In c++ we use a pointer to hold the reference of the memory address of an object but when we declare a variable it store it in the memory which is directly accessible. If there is no distinction between stack and heap then is a declaration (primitive type and box type) in javascript are reference type, maybe it's dumb question :) – Lord Apr 21 '20 at 21:40
-
JavaScript is a higher level language than C++ and it has a specification but how that is implemented is not specified, the engine is a black box. Unlike C++ you can't say what is really going on, apart from an implementation such as V8. – QuentinUK Apr 21 '20 at 22:45