JavaScript While Loop


JavaScript While Loop

  1. One of the special feature of an interpreter in reference with the for loop is that ___________.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Interpreter translates the source code into machine code line by line, and stops when it encounters an error. Before each iteration, the interpreter evaluates the variable expression and assigns the name of the property (a string value) to it.


  1. What will the following code snippet work? If not, what will be the error?
    function test(p) 
    {
    for (; p.next; p = p.next) ;
    return p;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    The above code uses a for loop to traverse a linked list data structure and return the last object in the list. This will perfectly work.



  1. What are the three important manipulations done in a for loop on a loop variable?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    In a for loop, the initialization, the test, and the update are the three crucial manipulations of a loop variable. Firstly the loop initialiases the variable then test the condition and then after executing the statement increments its value.


  1. Consider the following code snippet.
    function printArr(n) 
    {
    var len = n.length, p = 2;
    if (len == 2)
    console.log("Nothing is in Array");
    else
    {
    do
    {
    console.log(n[p]);
    } while (++p < len);
    }
    }

    What does the above code result?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    The do/while statement creates a loop that executes a block of code once, before checking if the condition is true, then it will repeat the loop as long as the condition is true. Hence the iterator traverse through the array and print them in normal order.