All the above true. I wasn't trying to be comprehensive.
One thing none of us mentioned but that tends to confuse the heck out of people new to this stuff:
Variables are *NOT* and *CAN NOT* be objects!
Variables *CAN* be (and commonly are) *REFERENCES* to objects.
I was careful in my prior post when I wrote
Quote:
|
Do you understand that? That says "create an object, referenced by the variable john, with the properties shown.
|
Even when we do
Code:
var john = new Person("john doe","john@xyz.com","Chief Gofer");
or even if we were to write (legal code!)
Code:
var object = new Object( );
those variables (john and object) are *NOT* objects. They are REFERENCES to objects.
It's a very important distinction! If I now write
Code:
var jane = john;
jane.name = "Jane Roe";
alert( john.name );
I will find that
john has changed his name to
Jane Roe!!!
Because all that
var jane = john did was copy the *reference* to the object. So we ended up with two references to the
same object.
So don't mistake references for actual objects. We treat them much the same, but they aren't the same.
********************
FWIW, this same distinction applies in Java and C# and, for the most part, in C++. (There are ways for a variable to actually *BE* an object in C++. Not commonly used, but...)