JavaScript does not provide a sizeof (like in C), and programmer does not need to care about memory allocation/deallocation. But how can we check how much memory an object occupies?
Let's say that you have a string:
var stringObject = String("Ala Eddine JEBALI");
How to implement a memorySizeOf function which returns the memory size of stringObject?
memorySizeOf(stringObject)
Let's say that you have this object:
var personObject = {persone: {name: 'Ala Eddine JEBALI', country: 'France', age: 30}};
How to implement a memorySizeOf function which returns the memory size of personObject?
memorySizeOf(personObject)
The result is of course the same when you want to check
console.log( memorySizeOf(123) );
or
console.log( memorySizeOf(Number(123)) );
The output is:
8 bytes