Valid JS-Dev-101 Dumps shared by EduDump.com for Helping Passing JS-Dev-101 Exam! EduDump.com now offer the newest JS-Dev-101 exam dumps, the EduDump.com JS-Dev-101 exam questions have been updated and answers have been corrected get the newest EduDump.com JS-Dev-101 dumps with Test Engine here:
Refer to the following array: let arr = [1, 2, 3, 4, 5]; Which two lines of code result in a second array, arr2, created such that arr2 is a reference to arr?
Correct Answer: C,D
The correct answers are C and D. Arrays in JavaScript are objects. When an array variable is assigned directly to another variable, both variables point to the same array in memory. Option C is correct: let arr2 = arr; This does not create a new array. It creates another reference to the same array. Example: arr2.push(6); console.log(arr); Output: [1, 2, 3, 4, 5, 6] Changing arr2 also affects arr because both variables reference the same array. Option D is also correct: let arr2 = arr.sort(); The sort() method sorts the array in place and returns the same array reference. Therefore, arr2 refers to the same array object as arr. The incorrect options create copies: let arr2 = arr.slice(0, 5); creates a shallow copy. let arr2 = Array.from(arr); also creates a new shallow copy. So the two lines that make arr2 reference the original arr are C and D.