Home / CSE / Javascript - CS :: Discussion

Discussion :: Javascript - CS

  1. Which is a more efficient code snippet ?
    Code 1 :

    for(var num=10;num>=1;num--)

    {

    document.writeln(num);

    }


    Code 2 :

    var num=10;

    while(num>=1)

    {

    document.writeln(num);

    num++;

    }

  2. A.

     Code 1

    B.

     Code 2

    C.

     Both Code 1 and Code 2

    D.

     Cannot Compare

    View Answer

    Workspace

    Answer : Option A

    Explanation :

    A for loop is always more efficient because it encapsules two individual statements(initialization and expression) within the braces.


Be The First To Comment