Lets consider an example of programming language C. There are multiple data types in C like int
, short
, char
etc. All of those data types has a specific disk size allocated to them. For eg. char
has a pre-specified size of 1 byte, short
has a size of 2 bytes and so on.
As, in JavaScript everything is an object, how you determine the size of an object (an array or string or number etc.)?
Just to understand my question here is a sample:
var array1 = [10, 20, 30];
var array2 = [];
var string1 = '';
var string2 = 'some value';
If we check the typeof
of anything above it returns object
. Now, I'm not able to understand how it allocates size to an object and what will be the exact amount of size allocated (because everything is an object and some objects my have big values, some might be empty, some might have very small values).