A

Admin • 833K Points
Coach

Q. Consider the following code snippet. What will be the output?

Code:
function printArray(a)
{
var len = a.length, i = 0;
if (len == 0)
console.log("Empty Array");
else
{
do
{
console.log(a[i]);
} while (++i < len);
}
}
  • (A) Prints the numbers in the array in order
  • (B) Prints the numbers in the array in the reverse order
  • (C) Prints 0 to the length of the array
  • (D) Prints “Empty Array”
  • Correct Answer - Option(A)
  • Views: 21
  • Filed under category JavaScript
  • Hashtags:

Explanation by: Admin

The do/while loop is less commonly used when compared to the while loop. Here, it prints from the array in the given order.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.