var arr1=[7,8,9]; var arr2=arr1; arr2[0]=8; document.write(arr1[0]); | Sololearn: Learn to code for FREE!

-1

var arr1=[7,8,9]; var arr2=arr1; arr2[0]=8; document.write(arr1[0]);

What happens here?

7/17/2020 1:19:11 PM

Rohit Ahuja

2 Answers

New Answer

+1

By arr2 = arr2, both variables points to same list so arr1[0] will changed to 8 by arr2[0]=8.

+1

Rohit Ahuja, you have completed enough courses to know how to use the code playground. So why haven't you typed it into the code playground and tried it? This reads like a challenge or quiz question. If you had executed the code you would know the result, and would have included it perhaps along with a question asking why that was the result and what you had expected.