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.
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.
发表评论
-
Extending Built-in Types
2009-01-08 13:55 725The Function.apply( ) method is ... -
Breakpoints using closures
2009-01-07 13:43 869// // This function implements ... -
Private properties with closures
2009-01-07 13:13 760// // This function adds proper ... -
Constructor Functions
2009-01-07 00:42 760the new operator creates a new ... -
Functions as Methods
2009-01-07 00:39 805When a function is invoked as a ... -
The callee Property
2009-01-07 00:02 664In addition to its array elemen ... -
Variable-Length Argument Lists: The Arguments Obje
2009-01-06 23:06 787The Arguments object has one ve ... -
Function Literals
2009-01-06 21:50 702Although function literals crea ... -
Nested Functions
2009-01-06 21:09 767Nested functions may be defined ... -
Deleting Array Elements
2009-01-05 22:11 567The delete operator sets an arr ... -
Reading and Writing Array Elements
2009-01-05 22:00 763Note that array indexes must be ... -
The valueOf() Method
2009-01-05 18:05 742... -
The toLocaleString() Method
2009-01-05 18:02 851In ECMAScript v3 and JavaScript ... -
The constructor Property
2009-01-05 17:51 789[size=medium]Since constructor ... -
the empty statement
2009-01-05 00:29 786[size=medium]When you intention ... -
with
2009-01-05 00:27 683[size=medium]The with statement ... -
try/catch/finnaly
2009-01-05 00:17 890If control leaves the try bloc ... -
throw
2009-01-04 23:56 691The tHRow statement has the fol ... -
return
2009-01-04 23:52 816If a function executes a return ... -
functions
2009-01-04 23:48 789[size=medium]Technically speaki ...
相关推荐
This chapter delves into the data types available in Java, including primitive types (such as `int`, `float`, and `char`) and reference types (such as `String` and `Object`). It also covers operators ...
C# primitive data types, value and reference types, implicitly typed variables, anonymous types, plus dynamic typing in C# 4.0 Methods and parameters–including extension methods, partial meth­...
Java 中有两种基本数据类型:primitive types 和 reference types。primitive types 包括整数、浮点数、字符、布尔值等,而 reference types 则包括类和接口。primitive types 的值是存储在栈中的,而 reference ...
Metal Primitive Types 113 Responding to MTKViewDelegate Methods 115 Retrieving a Drawable 115 Creating a Command Buffer 116 Creating a Command Encoder 117 Fixed-Function State on the Command ...
C# primitive data types, value and reference types, implicitly typed variables, anonymous types, plus dynamic typing in C# 4.0 Methods and parameters–including extension methods, partial methods, ...
–The difference between primitive and reference values –What makes JavaScript functions so unique –The various ways to create objects –How to define your own constructors –How to work with and ...
Java array and NIO Buffer arguments (primitive types and pointers) as pointer-to-buffer Nested structures and arrays Wide (wchar_t-based) strings Native long support (32- or 64-bit as appropriate)...
在类型、值和变量(Types, Values, and Variables)章节中,文档详细解释了Java类型系统的基础,包括各种类型和值的种类,其中既有基本类型(Primitive Types)也有引用类型(Reference Types),以及变量的定义和...
Java有两大类数据类型:**原始数据类型(Primitive Data Types)**和**引用数据类型(Reference Data Types)**。原始数据类型包括: 1. **整型**(Integers):如`byte`, `short`, `int`, `long`,分别表示8位、16...
CHAPTER 5 Primitive, Reference, and Value Types 111 CHAPTER 6 Type and Member Basics 151 CHAPTER 7 Constants and fields 175 chaPTer 8 Methods 181 chaPTer 9 Parameters 209 CHAPTER 10 Properties 227 ...
Chapter 8Primitives as Typesexplores the relationship between the primitive types and objects of their corresponding wrapper classes, and how boxing and unboxing can transparently convert between ...
The reference cards contain a complete list of all of the functions in OpenGL ES 3.0 along with all of the types, operators, qualifiers, built-ins, and functions in the OpenGL ES Shading Language. ...
Java中共有八种原始类型(Primitive Types),它们包括: 1. 整数类型:byte(1字节)、short(2字节)、int(4字节)和long(8字节)。 2. 浮点类型:float(4字节)和double(8字节)。 3. 字符类型:char(2字节...
它主要有两种数据类型:基本类型(Primitive Types)和引用类型(Reference Types)。基本类型包括字符串(String)、数字(Number)、布尔值(Boolean)、空值(null)、未定义(undefined)以及在ES6中新增的符号...
- **Simple Types:** Explains primitive data types such as integers, floats, and characters. - **Initialization:** Describes different methods of initializing variables. - **The Traditional Conversions...
Chapter 19: Primitive Data Types, Arrays, Loops, And Conditions Chapter 20: Functions Chapter 21: Objects Chapter 22: Prototype Chapter 23: Inheritance Chapter 24: The Browser Environment Chapter 25: ...
基本数据类型(primitive types):由程序设计语言系统所定义的,不可再划分;内存大小固定,存放数据本身;与软硬件环境无关。 引用类型(reference types):在内存中存放的是指向该数据的地址,不是数据本身;...