yes, any just by doing so, the author introduce a implicit dependencies between components. Using the same array all over the and somewhere it get emptied will cause some nice side effects.
Nope. If you had another reference to the original array, the original array would still remain at the other reference - you have done nothing to the original array.
Compare:
letnumbers=[1,3,5,7,9];letnumbers_b=numbers;// another reference to same arraynumbers.length=0;console.log(numbers_b);// []
And:
letnumbers=[1,3,5,7,9];letnumbers_b=numbers;// another reference to same arraynumbers=[];console.log(numbers_b);// [1, 3, 5, 7, 9]
Assigning to an empty array does exactly that - assigns a new array to the variable. Entirely different to emptying an existing array. 'Emptying' an array by simply overwriting it with a new empty array could easily cause unexpected problems.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Wouldnt it be the same assigning to an empty array?
let numbers = [] ;
I think Not..
Its the Same result but the author used the existing Array in context and you create an complete new Array for context
yes, any just by doing so, the author introduce a implicit dependencies between components. Using the same array all over the and somewhere it get emptied will cause some nice side effects.
This will give you some fun debugging session.
Nope. If you had another reference to the original array, the original array would still remain at the other reference - you have done nothing to the original array.
Compare:
And:
Assigning to an empty array does exactly that - assigns a new array to the variable. Entirely different to emptying an existing array. 'Emptying' an array by simply overwriting it with a new empty array could easily cause unexpected problems.