JavaScript Quiz

8 Questions | Total Attempts: 185

SettingsSettingsSettings
Please wait...
JavaScript Quizzes & Trivia

This will test your core concepts of the language


Questions and Answers
  • 1. 
    What does the below line do considering it as the first line in your javascript file (function(){alert(this)})();
    • A. 

      Nothing happens

    • B. 

      I will see an error

    • C. 

      I will see an alert with undefined value

    • D. 

      I will see an alert with null value

    • E. 

      I will see an alert with not null value

  • 2. 
    1. <input type="button" value="Button 1" id="btn1"  />  
    2. <input type="button" value="Button 2" id="btn2"  />  
    3. <input type="button" value="Button 3" id="btn3"  onclick="buttonClicked();"/>  
    4.   
    5. <script type="text/javascript">  
    6. function buttonClicked(){  
    7.     var text = (this === window) ? 'window' : this.id;  
    8.     alert( text );  
    9. }  
    10. var button1 = document.getElementById('btn1');  
    11. var button2 = document.getElementById('btn2');  
    12.   
    13. button1.onclick = buttonClicked;  
    14. button2.onclick = function(){   buttonClicked();   };  
    15. </script>  
    • A. 

      Clicking on button 3 displays btn3

    • B. 

      Clicking on button 3 displays null

    • C. 

      Clicking on button 3 displays undefined

    • D. 

      Clicking on button 3 displays something else

  • 3. 
    Apply or call method can be used to override the value of this
    • A. 

      True

    • B. 

      False

  • 4. 
    When used as a constructor, like new MyFunction(), the value of this will be a brand new object provided by the JavaScript runtime. If we don't explictly return anything from that function, this will be considered its return value.
    • A. 

      True

    • B. 

      False

  • 5. 
    When you create a plain Object , JavaScript will automatically assign a Prototype to each of these objects. This prototype will be Object.prototype.
    • A. 

      True

    • B. 

      False

  • 6. 
    The prototype for "hi" is String.Prototype , and the prototype for String.Prototype is Object.Prototype
    • A. 

      True

    • B. 

      False

  • 7. 
    Function Employee() { } Employee.ShowAge = function() {     alert("sss"); } This adds a static method to the Employee function which would not be available to the objects of   Employee function
    • A. 

      True

    • B. 

      False

  • 8. 
    Employee.prototype.constructor would be Employee be default. This needs to be explicitly set in the following scenario otherwise it would be Employee for Manager.constructor.prototype Manager.prototype = new Employee(); Manager.constructor.prototype = Manager;
    • A. 

      True

    • B. 

      False