Primitive Types and Reference Types
By value versus 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. |
Numbers and booleans are primitive types in JavaScript
Object and Array are reference types
String : when pass as arg in function, I dont care, because you have not way to modi the string, when it is compare, it is by value. when it is copied, by value too.