Record collection need explanation

hi, I understand lessions of javaSctipt curriculum so far until this, this confused me: " to modify the object passed to the function." i googled how object can be passed to a function
and figured out that objects are passed to a function by reference… and reference in this case is “album title” or “artist” …and there is function call down like this (updateRecords(recordCollection, 5439, ‘artist’, ‘ABBA’));
so… when i console.log(2548) it displays album, artist and tracks…that is good
assigment is to Complete the function using the rules below to modify the object… if you modify the object it shoud have all propertyes isn’t it? …passed to the function., rules are:

  • Your function must always return the entire record collection object.
  • If prop isn’t tracks and value isn’t an empty string, update or set that album’s prop to value .
  • If prop is tracks but the album doesn’t have a tracks property, create an empty array and add value to it.
  • If prop is tracks and value isn’t an empty string, add value to the end of the album’s existing tracks array.
  • If value is an empty string, delete the given prop property from the album.

I solved the lesson with hint solution, but still dont understand what is purpose of that function if it adds a value and return records, why can’t I console log records and value? in function updateRecords there is 4 parameters: records, id, prop, and value… id are numbers or names of objects… prop are artist and tracks.
but what are value and records…
sorry because of that I can’t explain problem better, it would be great if someone could explain me in simple words or give me specific material,literature where I can figure that out,

   **Your code so far**

// Setup
const recordCollection = {
 2548: {
   albumTitle: 'Slippery When Wet',
   artist: 'Bon Jovi',
   tracks: ['Let It Rock', 'You Give Love a Bad Name']
 },
 2468: {
   albumTitle: '1999',
   artist: 'Prince',
   tracks: ['1999', 'Little Red Corvette']
 },
 1245: {
   artist: 'Robert Palmer',
   tracks: []
 },
 5439: {
   albumTitle: 'ABBA Gold'
 }
};

// Only change code below this line
function updateRecords(records, id, prop, value) {
if (prop !== "tracks" && value !== ""){
  records[id][prop] = value;
}else if (prop == "tracks" && records[id].hasOwnProperty("tracks")=== false){
  records[id][prop] = [value];
}else if (prop === "tracks" && value !== ""){
records[id][prop].push(value);
 }else if (value == ""){
   delete records[id][prop];
 }

  return records;
}

(updateRecords(recordCollection, 5439, 'artist', 'ABBA'));

   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36

Challenge: Record Collection

Link to the challenge:

records is the object that the function should change

value is the value used to updated the prop

how to console.log/display records? , records are, artists, tracks, album title, i get it, but id is object name i know that but shouldn’t function add other values to the objects or what is that function used for what is its purpose

If you look at one of the objects of recordCollection (which is passed as the records argument of the function), you see

{
  2548: {
    albumTitle: 'Slippery When Wet',
    // ...
  },
  // ...
}
  • The whole object gets passed as the records parameters
  • 2548 is what corresponds to an id
  • albumTitle is what corresponds to a prop
  • 'Slippery When Wet' is what corresponds to a value

Your function will need to find the correct nested object to update via the id, update the correct property of that object via the prop, and update it with the correct data via value.

if you write console.log(records) inside the function it will be logged to the console

where is set that records presents an id prop and value?

yes, global and local scope that is lession right i was trying console log outside of function

by definition records will have that structure, otherwise the function is not able to work on the object

I would understand if id , in this case name of object is something what you use to modify object but records are not mentioned not in name of object not in properties,

Are you confused about the connection between the recordCollection variable, and the records function parameter?

yes, how can you use variable values with some other name other than that variables name

The recordCollection variable is passed to the function as an argument when you call the function. This line at the bottom of the starter code calls the function.

updateRecords(recordCollection, 5439, 'artist', 'ABBA');

This passes recordCollection as the first argument.


If we look at the updateRecords function definition, we can see that the first parameter is named records. You can see the function definition on this line.

function updateRecords(records, id, prop, value) {

So, since recordCollection is passed to the function as the records parameter, both of those names refer to the same object (since as you said, objects are pass-by-reference).

OK now I get it , but it is not simple to figure it out if there is no = operator what says: that- is same as- that.
thank You for your effort to explain