Hi Guys!
I’m reviewing Javascript and got to Record Collection challenge again. The first time it took me quite a long time to figure out a code that works. A week later, I revisited to see if I am still able to get the solution on my own, which I did, even faster than the first time.
However, I looked at their solution under “Get a hint”, and have a question about their solution:
function updateRecords(id, prop, value) {
if (prop === "tracks" && value !== "") {
if(collection[id][prop]) {
collection[id][prop].push(value);
}
else {
collection[id][prop]=[value];
}
} else if (value !== "") {
collection[id][prop] = value;
} else {
delete collection[id][prop];
}
return collection;
}
What is the difference between:
collection[id][prop]=[value];
and
collection[id][prop] = value;
?
They use both in their solution. I reviewed how to update object properties in previous lessons, and the only guess I can make is that the first one makes it an array, and the second one stores it as whatever data type ‘value’ brings.
Is that correct?
Thanks, all!