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) घ...
‘ महात्मा’ शब्द का सही संधि-विच्छेद क्या है ?
निम्नलिखित प्रश्न में , चार विकल्पों में से , उस सही विकल्प...
इनमें से कौन शब्दालंकार नहीं है?
सम्मान का विलोम शब्द क्या होगा?
दिए गए वाक्य में काले शब्द का तत्सम शब्द ज्ञात कीजिए।
च...
उच्चारण शब्द मे उपसर्ग है –
निम्नलिखित प्रश्न में विषम शब्द का चयन करे ?
चंद्रमा