I don't understand how using record.prop
is different than using record[prop]
inside functions when they give the same output outside functions, as shown below:
var ourDog = {
"name": "Camper"
};
ourDog.bark = "bow-wow";
function update(record, prop) {
record.prop = "cannot";
record[prop] = "woof";
return record;
}
console.log(update(ourDog, "anotherbark"));
Basically when I use dot instead of brackets, the property doesn't change to anotherbark
but instead remainds as prop
as shown in the result below:
{
"name": "Camper",
"bark": "bow-wow",
"prop": "cannot",
"anotherbark": "woof"
}