Unit 7 Objects 31 Properties


#1

I don't understand the purpose of this exercise at this point. I don't know why we would be saving a property that is already created into a variable. I kept trying to add the value to the property to store in the variable but I guess it's accessing the value from the property in the object ? Is that what this exercise is trying to show? That we're trying to get something out of the object as opposed to putting it in? If so, I'm not sure why we would create the variable with the same name as the property ... it's a bit confusing. Any insight would be helpful. Thank you in advance.

var snoopy = new Object();
snoopy.species = "beagle";
snoopy.age = 10;

// save Snoopy's age and species into variables
// use dot notation for snoopy's species
var species = snoopy.species;

// use bracket notation for snoopy's age
var age = snoopy["age"];


#2

@digitalwhiz95807,
What theyare trying to demonstrate
is the usage of
the so-called dot-notation versus the bracket-notation

===============================================

var friends= {
              bill: { firstName: 'Bill',
                      lastName: 'Gates',
                      number: '444-444-4444',
                      address: [ 'One Microsoft way', 'Redwood', 'WA' ]
              },
             steve: {
                      firstName: 'Steve',
                      lastName: 'Jobs',
                      number: '333-333-3333',
                      address: [ 'Two infinite loop', 'Bentown', 'DV' ] 
              }
   };

keep repeating these two lines
An object has one or more properties seperated by a comma-,
Each property consists of a property-key and it's associated value

Description of the friends object.
The friends object has 2 properties and are seperated by a comma-,

there is a bill property with property-key bill and it's associated object value
(this associated object has 4 properties, the property-keys being firstName, lastName,number and address)
there is a steve property with property-key steve and it's associated object value
(this associated object has 4 properties, the property-keys being firstName, lastName,number and address)

access via dot-notation == only literal property-key allowed

friends.bill ==> you will get the associated value of the bill property-key, thus
you get the object with 4 properties

friends.bill.lastName ==> you will get the associated value of the lastName property-key

access via the square-bracket-notation == literal & VARIABLE

1 using the literal property-key

friends["bill"]
friends["bill"]["lastName"]

2 using the property-key by reference (=== via a variable )

var propertyKey1 = "bill";
var propertyKey2 ="lastName";
friends[propertyKey1] ==> you will get the associated value of the bill property-key, thus
you get the object with 4 properties

friends[propertyKey1][propertyKey2]
in this case you will get the string VALUE of the lastName property
of the associated object VALUE of bill


#4

Wow!
I have passed by this a couple of times and just scanned the first couple of paragraphs...
sighed and went on to the next search result.

But, this time I actually stopped and tried to read and actually understand what you are trying to convey.
WOW! This should be incorporated into the lessons some how.
Which I guess it probably is somewhere down the road.
I have become MORE aware! thank you Leonhard.wettengmx.n