Question
Consider the following code: Â Â let data = [1,
2, 3]; Â Â function modifyArray(arr) { Â Â Â Â arr.push(4); Â Â Â Â arr = [5, 6]; // Reassigns local 'arr' Â Â Â Â return arr; Â Â } Â Â let result = modifyArray(data); Â Â console.log(data); Â Â console.log(result); Â Â What will be the output?Solution
1. data is [1, 2, 3].   2. modifyArray(data) is called. arr inside the function initially refers to the same array as data.   3. arr.push(4) modifies the original array that data also points to. So, data is now [1, 2, 3, 4].   4. arr = [5, 6] reassigns the local variable arr to a new array [5, 6]. This does not affect the data variable in the global scope.   5. The function returns the new array [5, 6], which is assigned to result.   Therefore, data is [1, 2, 3, 4] and result is [5, 6].
A container holds a mixture of juice and water in the ratio of 5:2. When 6 liters of juice are added to the mixture, the ratio of...
A sum of Rs. 'Y' was invested for 7(1/4) years at simple interest of 8(2/5)% p.a. such that the simple interest received was Rs. 5,115.60. Find the si...
The angle between the planes x − y + z = 1 and 2x + y − 3z = 5 is:
A trapezoid has bases of lengths 10 cm and 20 cm and an area of 180 cm². Find the height of the trapezoid.
Find the area enclosed between the curve y = √(25 – x²) and the x-axis in the first quadrant.
Which of the following scheduling algorithms is designed to reduce the turnaround time and waiting time in a multitasking environment?
A frustum of a cone has a lower base radius of 5 cm, an upper base radius of 3 cm, and a height of 4 cm. What is the volume of the frustum?
A trader buys a stock at an average price of Rs. 240 per share. He sells one-third of his shares at a 10% profit and the remainin...
A can complete a piece of work in 12 days, B in 18 days, and C in 36 days. They all work together for a few days, after which A leaves. B and C continue...
The ratio of the ages of A and B is 3:4. Five years later, the ratio of their ages will be 4:5. What are their present ages?