Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does JS always use two bytes per character to store strings?

I'm storing a very large ( >1MB ) bitmask in memory as a string and am curious about how JS stores strings internally. I have the feeling, based on the fact that

String.fromCharCode( 65535 ).charCodeAt( 0 ) === 65535

, that all strings are unicode, but I'm not certain. Basically I'm trying to find out if it would be more efficient, in terms of memory usage, to bitmask against 16-bit characters than 8-bit characters?

like image 833
Nobody Avatar asked Mar 06 '13 23:03

Nobody


1 Answers

Check this out:

https://developer.mozilla.org/en-US/docs/Mozilla_internal_string_guide#IDL_String_types

I believe it is very very browser dependent but the Mozilla documentation sheds some light on how they do it internally for JS strings.

The short answer is they use UTF-16

http://en.wikipedia.org/wiki/UTF-16

like image 92
Daniel Williams Avatar answered Sep 19 '22 17:09

Daniel Williams