gpt4 book ai didi

javascript - JavaScript 字符串如何是一组 "elements"16 位无符号整数值?

转载 作者:行者123 更新时间:2023-11-28 19:03:04 26 4
gpt4 key购买 nike

来自MDN

JavaScript's String type is used to represent textual data. It is a set of "elements" of 16-bit unsigned integer values. Each element in the String occupies a position in the String. The first element is at index 0, the next at index 1, and so on. The length of a String is the number of elements in it. You can create strings using string literals or string objects.

JavaScript String 类型为何是一组 16 位无符号整数值的“元素”,为什么不是 8 位无符号整数值?

最佳答案

查看full spec text这里有帮助:

The String type is the set of all ordered sequences of zero or more 16-bit unsigned integer values (“elements”) up to a maximum length of 253-1 elements. The String type is generally used to represent textual data in a running ECMAScript program, in which case each element in the String is treated as a UTF-16 code unit value.

类似的可以在ES5.1 spec中找到.

为什么不是 8 位无符号整数值?如果使用 UTF-8,这同样是可能的。但它并没有完成,现在就是这样。

关于javascript - JavaScript 字符串如何是一组 "elements"16 位无符号整数值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32182786/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com