JavaScript Statements


JavaScript Statements

  1. Which is a more efficient code snippet?
    Code 1 :
    for(var n=10;n>=1;n--)
    {
    document.writeln(n);
    }


    Code 2 :

    var n=10;
    while(n>=1)
    {
    document.writeln(n);
    n++;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Code 1 would be more efficient. Infact second code will go into runtime error as the value of num will never reach less than or equal to one.


  1. A conditional expression is also called a _______________.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    A conditional expression can evaluate to either True or False based on the evaluation of the condition. If the condition is true then the value following the operator is taken that’s why it is called immediate if.



  1. A conditional expression is also called a _______________.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    A conditional expression can evaluate to either True or False based on the evaluation of the condition. If the condition is true then the value following the operator is taken that’s why it is called immediate if.


  1. What would be the most appropriate output for the following code snippet?
    var p=15 , q=10
    var object = { p : 20 }
    with(object)
    {
    alert(q)
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Firstly the interpreter checks obj for property b.But it doesn’t find any property b so it takes the value from outside the object within the code snippet.



  1. JavaScript is a _______________ language.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    JavaScript is not a full-blown OOP (Object-Oriented Programming) language, such as Java or PHP, but it is an object-based language. The criteria for object orientation are the classic threesome of polymorphism, encapsulation and inheritance and JavaScript doesn’t pass this.