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 man can row 25/2 km an hour in still water and he finds that it takes him thrice as long to row up as to row down the river. The rate of stream is:
The speed of a boat is that of the current of water is 30:7. The boat goes along with the current in 4 hours 12 minutes. It will come back in
A boat takes half the time to move a certain distance downstream than upstream. the ratio of the boat's speed in still water and that of the current is.
A man can row at 30 km/hr in still water. If the velocity of current is 6 km/hr and it takes him 1 hour to row to a place and come back, how far is the ...
A man can row at 2 kmph in still water. If the velocity of current is 1 kmph and it takes him 4 hour to row to a place and come back, how far is the place?
A boat can cover 187 km in downstream in 11 hours and 180 km in upstream in 18 hours. Find the speed of boat in still water
A boy can swim in water with a speed of 10 km/hr in still water. If the speed of the stream is 6 km/hr, what will be the time taken by the boy to cover ...
A boat takes 7 hours to cover 266 km upstream and 9 hours to cover 468 km downstream. Find the time taken by the boat to cover 528 km upstream and 540 k...
A man can row 5 km/hr in still water. If the speed of the current is 2 km/hr, it takes 4 hours more in upstream than in the downstream for the same dist...
The speed of the boat upstream and downstream are in the ratio of 3:4. If the boat covers a distance of 147 km in still water in 7 hours, determine the...