Hello, everyone!
I’m new to the forum, so I’m sorry if my topic isn’t appropriate in here.
I have a fundamental problem for JavaScript. Before my explanation, I’d like you to see the following example.
int n = 123;
In the worlds like Java, C and so on, as you know, the programme reserves 4 bytes on the memory. On the one hand, in the world of JavaScript, the int becomes the var and the line is referred to as the Number type. But the Number type includes the int, double and so on, so the size of memory isn’t fixed.
Like the line, we call that a variable gets a value initialisation. In the world of JavaScript, we can declare a variable without the initialisation.
var n;
This variable may be a number or a string. We don’t know until initialising it.
So, my question is, how many bytes does the programme reserve on the memory for the latter case, with and without the initialisation?
I think my question is same for Ruby, Python and so on.
Thank you for reading!
Hello @safejourney
you can think of it as java 10 new option that make you able to use var
var x = 5;
hope that help and have a nice day 
1 Like
Hello, justsomeone!
Thank you for answering my question.
Your comment reminded me of Java and gave me a new point of view. I really appreciate. But unfortunately, your comment couldn’t fix my question.
The point is the initialisation. As you mentioned, we can use var in Java too but the var in Java requires the initialisation at the same time and the programme recognises the type by it. On the one hand, the var in JavaScript doesn’t require.
But lastly, I’d like to appreciate your help again.
you very welcome @safejourney
check this
Memory management - JavaScript | MDN
and also use this js file to get the size of any object you like to know about
http://code.iamkate.com/javascript/finding-the-memory-usage-of-objects/
hope it help and have a nice day 
1 Like
I really thank you justsomeone!
The sizeof.js library you taught me was very fantastic and I will utilise it for my applications.
Thanks to you, I knew how top-level programmers think the memory management or they count each type. But just one thing I don’t know still remains. They all recognise or define the size of undefined type as zero. But JavaScript allows us not to initialise a variable and then some bytes are reserved, I think it’s not zero.
I wrote as above, but I stopped here and rethought it.
Zero may be correct, which may be reserved for a variable which is not initialised, namely undefined type.
No posts mentioned it explicitly but it’s very interesting if it’s correct.
I really appreciate you, justsomeone.
This topic is not closed because I’m not sure whether it’s yes or no.
Any other comments, very welcome.
you very welcome @safejourney
actually thanks for you who make me dive into that and learn something new
my guess to the zero size of only declared variable that as you know
some lanagage require complie like c c++ which other complied to middle state like the case in java the .class file
but in html css and js the browser are the one who responsible for interpret
the file so it can create actule variable and researve a memory to it or even do not till the variable needed
but if you need to really dine into that then you should read about how the Gecko (firefox js engine) or v8 (the chrome one) work so you know how it work
you very welcome and thanks for you
hope that help and have a nice day 
1 Like