gpt4 book ai didi

javascript - javascript 中的字符串

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:02:44 24 4
gpt4 key购买 nike

我最近看到一些引用资料将Javascript中的字符串解释为原始类型。我知道原始类型是一种数据类型,它不由其他数据类型组成,不能进一步分解。但问题是我也读过字符串是对象。它怎么可能是两者?请澄清我的困惑。

最佳答案

您可以在 MDN 上阅读有关该确切主题的信息:

Note that JavaScript distinguishes between String objects and primitive string values. (The same is true of booleans and numbers.)

String literals (denoted by double or single quotes) and strings returned from String calls in a non-constructor context (i.e., without using the new keyword) are primitive strings. JavaScript automatically converts primitives to String objects, so that it's possible to use String object methods for primitive strings. In contexts where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript will automatically wrap the string primitive and call the method or perform the property lookup.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

关于javascript - javascript 中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18167045/

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