primitive datatype and wrapper objects
1. each of the three primitive datatypes (number,string,boolean) has a corresponding
object class defined .That is, besides supporting the number, string, and boolean
datatypes, JavaScript also supports Number, String, and Boolean classes. These classes
are wrappers around the primitive datatypes. A wrapper contains the same primitive data
value, but it also defines properties and methods that can be used to manipulate that data.
2.the object created when use the primitive types in an object context is a transient one.
3.note that any number, string, or boolean value can be converted to its corresponding
wrapper object with the Object( ) function:var number_wrapper = Object(3);
object-to-primitive conversion
1.note that whenever a non-null object is used in a Boolean context, it converts to true
2.all wrapper objects convert to true ,even its primitive values that convert to false.
by value versus by reference
By value
By reference
Copy |
The value is actually copied; there are two distinct, independent copies. |
Only a reference to the value is copied. If the value is modified through the new reference, that change is also visible through the original reference. |
Pass |
A distinct copy of the value is passed to the function; changes to it have no effect outside the function. |
A reference to the value is passed to the function. If the function modifies the value through the passed reference, the modification is visible outside the function. |
Compare |
Two distinct values are compared (often byte by byte) to see if they are the same value. |
Two references are compared to see if they refer to the same value. Two references to distinct values are not equal, even if the two values consist of the same bytes. |
javascript rule:
primitive types are manipulated by value,reference types are
manipulated by reference.
2.for efficiency, JavaScript strings are (presumably) copied and passed by reference, they are compared by value.