Primitive Types and Reference Types

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.

你可能感兴趣的:(JavaScript)