Numbers are 8 bytes.
Found on this page w3schools .
I searched a bit more for other primitive JavaScript types, but it is surprisingly hard to find this information! However, I found the following code:
... if ( typeof value === 'boolean' ) { bytes += 4; } else if ( typeof value === 'string' ) { bytes += value.length * 2; } else if ( typeof value === 'number' ) { bytes += 8; } ...
It seems to indicate that the string has 2 bytes per character, and the logical one has 4 bytes.
Code found here and here . The complete code actually used to get the approximate size of the object.
Although after further reading, I found this interesting konijn code on this page: The number of bytes in bytes is a string .
function getByteCount( s ) { var count = 0, stringLength = s.length, i; s = String( s || "" ); for( i = 0 ; i < stringLength ; i++ ) { var partCount = encodeURI( s[i] ).split("%").length; count += partCount==1?1:partCount-1; } return count; } getByteCount("iâ¥js");
Thus, the line size in memory depends on the characters themselves. Although I'm still trying to understand why he set the counter to 1, if it is 1, otherwise he took count-1 (in the for loop).
The post will be updated if I find anything else.
Raani kheir
source share