Ad
  • Custom User Avatar

    b=[...a] for instance would create a deep copy, meaning it really allocate new space withing the memory with the copied data.
    b=a just copy the reference points, so if you alter or access the memory by using either reference a or b it will change the same data in the same location.

    There are more to shallow and deep copies in javascript. For instance, if you have a nested array on the copied array, b=[...a] will not deep copy it. It will deep copy the memory reference to the nested array, but the data of such array in the memory is still the same in either a or b.

    Hope I helped!

    Have a nice video about the theme!
    https://www.youtube.com/watch?v=EeZBKv34mm4