In JS, does 'a' occupy 2 bytes or 1 byte in memory?
世界只因有你
世界只因有你 2017-07-05 10:46:22
0
2
1193

1. In JS, does 'a' occupy 2 bytes or 1 byte in memory? JS is encoded in UCS-2, so it should take up 2 bytes, right?

2. Are JS strings encoded the same in different engines?

3. In JS, how does a string represent the "end" in memory? Is it also necessary to add a \0?

世界只因有你
世界只因有你

reply all(2)
某草草

String global object
Read the documentation first~

洪涛

Let me answer what I know:

1) The a letter (the first lowercase one in English) takes up two bytes. JS uses UCS-2, but it was later compatible with UTF16.

But some rare words may not necessarily be 2 bytes in length, but may be multiple. For relevant knowledge, you can find Ruan Yifeng’s explanation of string knowledge. It is also recommended to read it

Look at the relevant entries in the Wiki and refer to the reference links below (mainly documents from standardization organizations).

2) The encoding is stipulated by ECMA and is the same. As a scripting language, its encoding is determined by the ECMA document.

3) This is related to the engine.

You can refer to the reply to this question

https://www.zhihu.com/questio...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template