Great work! You just created your very first object.
There are two ways to create an object: usingobject literal notation (which is what you just did) and using the object constructor.
Literal notation is just creating an object with curly braces, like this:
varmyObj = {
type:'fancy',
disposition:'sunny'};varemptyObj = {};
When you use the constructor, the syntax looks like this:
varmyObj =newObject();
This tells JavaScript. "I want you to make me anew
thing, and I want that thing to be anObject
.
You can add keys to your object after you've created it in two ways:
myObj["name"] ="Charlie";myObj.name="Charlie";
Both are correct, and the second is shorthand for the first. See how this is sort of similar to arrays?