Tell us what’s happening:
Describe your issue in detail here.
Okay I just completed the record collection challenge, this post is more me seeking understanding than a solution to a problem . I wrote my code according to the instructions using dot notation and it didn’t test successfully but when I checked the solutions on the hint page and switched to bracket notation as used in the solutions it was successful. I feel like I might be missing something really simple here but could someone please explain why it is so?
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36.
So, the link I pasted above does explain the difference. In your case:
id is a variable (in this updateRecords function it comes as a parameter). So, is prop.
records.id looks for the property id in the object literal records. Here is an example of the object literal records:
var records = {
2548: {
albumTitle: 'Slippery When Wet',
artist: 'Bon Jovi',
tracks: ['Let It Rock', 'You Give Love a Bad Name']
},
}
This object literal does not have the property id. So, trying to access records.id yields undefined. Same goes for id.prop - record.id does not exist, therefore id.prop does not exist.
Think about what happens when the code is compiled:
const myObj = { 1234: { someProp: "some val" } };
const obj2 = { id: { otherProp: "val 2" } };
const id = 1234;
console.log(myObj.id) // undefined
console.log(obj2.id) // { otherProp: "val 2" }
console.log(myObj[id]) // You test this, and see what happens
Hope this clarifies. If not, be sure to ask specific questions we can work through.