4. add prop. (dots question)


#1



https://www.codecademy.com/courses/javascript-beginner-en-3bmfN/0/4?curriculum_id=506324b3a7dffd00020bf661#


Can i write like that with a lot of dots? It lets me move to next challenge, but feels wierd, just curious.

var friends = {};

    friends.bill = {};
        friends.bill.firstName = "Bill",
        friends.bill.lastName = "Gates",
        friends.bill.number = "345"
    

    friends.steve = {
       firstName: "Steve",
       lastName: "Jobs",
       number: "123"
    };


#2

This way is fine except it is a statement, so ends with ;, not ,. The object literal is easier to read, and write. We can nest the ojbects, as well, to make it even more explicit:

var friends = {
    steve: {},
    bill: {}
};

#3

Oh yes ofcourse semicolons. Ye, i agree about object literal way, i wrote that just for training. Thanks :grin: