1

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).

Sanjay Joshi
  • 2,036
  • 6
  • 33
  • 48
  • https://stackoverflow.com/questions/1248302/how-to-get-the-size-of-a-javascript-object – Krushnakant Ladani Oct 10 '17 at 05:06
  • `typeof string1 === 'string'`. `typeof string2 === 'string'`. – StackSlave Oct 10 '17 at 05:08
  • 2
    There's nothing in the ECMAScript spec that defines implementation-specifics of objects, so your runtime could allocate as much space as it wants for objects. If you want specifics, you'll need to look at the details of a specific Javascript runtime/engine, for example V8, to see how it handles things like allocation of objects. – jackarms Oct 10 '17 at 05:13
  • js is dynamically typed, there are no specific footprint sizes like in pre-compiled languages – dandavis Oct 10 '17 at 05:19

0 Answers0