Arr3 = arr3.join('') works but not arr3.join('')

Hello, I am doing the Basic Algorithm : Confirm the Ending, and found that the below works (arr3 will be be joined without commas) :-

 let arr3 = arr1.slice(diff,check1);
 arr3 = arr3.join('');

but not this (arr3 will still have commas) :-

 let arr3 = arr1.slice(diff,check1);
 arr3.join('');

Is it possible to maybe point me to an article on the reason for this? Thank you.

join() returns an array, it doesn’t change the variable on which it is used. ergo, with arr3 = arr3.join('') you are changing arr3, in the other way you are not

2 Likes