Learn Fetch and Promises -- setting array to data from fetch

To those experienced in JS SWE, I’m wondering why in this lesson (step 14) we set the authorDataArr equal to the data from the fetch. My understanding is that this simply creates a pointer to the data from the fetch. But in this circumstance, when dealing with data imported from a fetch, isn’t it generally considered better practice to copy the data? I was thinking something like
would have been used instead. What are the pros and cons of each approach?


  • have you tried using that?
  • what do you think “data” consists here?
  • what is type of “data” that is being received from “fetch”

happy coding :slight_smile:

1 Like

As long as you are using non-mutating methods it doesn’t really matter. But if you plan on mutating the data structure it may be necessary to make a copy first.

But I wouldn’t say always making a copy is a good idea, at least not from a performance point of view. If you make a copy but never mutate the data the copy is just overhead.

1 Like

Thank you both for your answers!