Primitive Types and Reference Types

[size=medium]Numbers and booleans are primitive types in JavaScriptprimitive because they consist of nothing more than a small, fixed number of bytes that are easily manipulated at the low levels of the JavaScript interpreter. Objects, on the other hand, are
reference types. Arrays and functions, which are specialized types of objects, are therefore also reference
types. These datatypes can contain arbitrary numbers of properties or elements, so they cannot be manipulated as easily as fixed-size primitive values can. Since object and array values can become quite
large, it doesn't make sense to manipulate these types by value, because this could involve the inefficient
copying and comparing of large amounts of memory.
What about strings? A string can have an arbitrary length, so it would seem that strings should be
reference types. In fact, though, they are usually considered primitive types in JavaScript simply because
they are not objects. Strings don't actually fit into the primitive-versus-reference type dichotomy.

JavaScript strings are (presumably) copied and passed by reference, they are compared by value.

Numbers, boolean values, and the null and undefined types are primitive. Objects,
arrays, and functions are reference types.
[/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值