I am learning Javascript and have a question regarding objects. In a lesson I saw an object created like this:
var friends = {};
friends.john = {
firstName: "John",
lastName : "Doe",
id : 5566,
fullName : function() {
return this.firstName + " " + this.lastName;
}
};
Is john in friends.john a key who's value is what's in the curly braces? I do not understand when an object is first created with the dot notation vs. just putting everything into the curly braces to begin with.
console.logfor debugging, you'll see the structure of your object.johnproperty within definition offriends, the magic infriends.john = {...}is, that you can add properties to an object at any time after it has been defined.friends.john(orfriends['john']) is how you access/set a key after the object has been declared. Setting it is the same asfriends = {john: {}}.