Trivia On JavaScript: MCQ Quiz

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Akshayswaroop
A
Akshayswaroop
Community Contributor
Quizzes Created: 1 | Total Attempts: 551
Questions: 8 | Attempts: 551

SettingsSettingsSettings
Trivia On JavaScript: MCQ Quiz - Quiz

.


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

    Correct Answer
    E. I will see an alert with not null value
    Explanation
    In a function called directly without an explicit owner object, like myFunction(), causes the value of this to be the default object (window in the browser).

    Rate this question:

  • 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

    Correct Answer
    D. Clicking on button 3 displays something else
    Explanation
    In a function called directly without an explicit owner object, like myFunction(), causes the value of this to be the default object (window in the browser). In a function called using the method invocation syntax, like obj.myFunction() or obj['myFunction'](), causes the value of this to be obj.

    Rate this question:

  • 3. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The statement is true because both the apply and call methods can be used to override the value of "this" in JavaScript. These methods allow you to explicitly set the value of "this" within a function, allowing you to control the context in which the function is executed. This can be useful when you want to invoke a function with a specific object as the value of "this", rather than the default value determined by how the function is called.

    Rate this question:

  • 4. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    When a function is used as a constructor with the "new" keyword, it creates a new object. The value of "this" inside the constructor refers to this newly created object. If the constructor function does not have an explicit return statement, the newly created object will be considered as the return value. Therefore, the statement "When used as a constructor, like a new MyFunction(), the value of this will be a brand new object provided by the JavaScript runtime. If we don't explicitly return anything from that function, this will be considered its return value" is true.

    Rate this question:

  • 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

    Correct Answer
    A. True
    Explanation
    When creating a plain Object in JavaScript, a prototype is automatically assigned to each of these objects. This prototype is set to Object.prototype. Therefore, the statement "When you create a plain Object, JavaScript will automatically assign a Prototype to each of these objects. This prototype will be Object.prototype" is true.

    Rate this question:

  • 6. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The statement is true because in JavaScript, every object has a prototype, which is an object from which it inherits properties and methods. The prototype for the string "hi" is String.prototype, which is the prototype object for all string objects. And the prototype for String.prototype is Object.prototype, which is the prototype object for all objects in JavaScript. Therefore, the prototype chain for "hi" goes from String.prototype to Object.prototype.

    Rate this question:

  • 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

    Correct Answer
    A. True
    Explanation
    This code adds a static method called ShowAge to the Employee function. Static methods are attached to the function itself, rather than the objects created from the function. Therefore, this method would not be available to the objects created from the Employee function. This statement is true.

    Rate this question:

  • 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

    Correct Answer
    A. True
    Explanation
    In JavaScript, when an object is created using a constructor function, its prototype property is automatically set to the constructor's prototype object. In the given scenario, the Manager object is created using the Employee constructor, so its prototype property would be set to the Employee constructor's prototype object. Therefore, the statement "Manager.prototype = new Employee();" sets the prototype of Manager to the Employee constructor's prototype object. And the statement "Manager.constructor.prototype = Manager;" sets the constructor's prototype of Manager to itself. Hence, the correct answer is true.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 15, 2012
    Quiz Created by
    Akshayswaroop
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.