0 votes
in JavaScript by
Which of the following is the correct output for the following JavaScript code:

functiondisplayArray(x)  

{  

varlen=x.length,i=0;  

if(len==0)  

console.log("Empty Array");  

else  

{  

do  

{  

             console.log(x[i]);  

} while (++i<len);  

}  

}  

a) Prints the numbers in the array in the reverse order

b) Prints the numbers in the array in specific order

c) Prints "Empty Array"

d) Prints 0 to the length of the array

1 Answer

0 votes
by

Answer: B

Reason: As we all know, the "do-while" statement creates a loop that runs at least once even if the given condition is not satisfied. This is because it runs for the first time before checking the condition, and then executes until the condition becomes false. Therefore, it traverses the array and prints the element of the array on the screen in a specific order.

Related questions

0 votes
asked Mar 20, 2021 in JavaScript by sharadyadav1986
0 votes
asked Mar 21, 2021 in JavaScript by rajeshsharma
...