Trivia On JavaScript: MCQ Quiz

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Akshayswaroop
A
Akshayswaroop
Community Contributor
Quizzes Created: 1 | Total Attempts: 555
| Attempts: 555 | Questions: 8
Please wait...
Question 1 / 8
0 %
0/100
Score 0/100
1. When you create a plain Object, JavaScript will automatically assign a Prototype to each of these objects. This prototype will be Object.prototype.

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.

Submit
Please wait...
About This Quiz
Trivia On JavaScript: MCQ Quiz - Quiz

This JavaScript MCQ quiz tests knowledge on various aspects of JavaScript coding, including function context, event handling, and prototype chains. It assesses understanding of how 'this' keyword behaves... see morein different scenarios, enhancing skills in writing and debugging JavaScript. see less

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

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.

Submit
3. 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.

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.

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

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.

Submit
5. 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;

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.

Submit
6. 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

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.

Submit
7.
  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>  

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.

Submit
8. What does the below line do considering it as the first line in your javascript file (function(){alert(this)})();

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).

Submit
View My Results

Quiz Review Timeline (Updated): Mar 22, 2023 +

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
Cancel
  • All
    All (8)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
When you create a plain Object, JavaScript will automatically assign a...
The prototype for "hi" is String.Prototype , and the...
When used as a constructor, like a new MyFunction(), the value of this...
Apply or call method can be used to override the value of this.
Employee.prototype.constructor would be Employee be default. This...
Function Employee() {...
<input type="button" value="Button 1" id="btn1"  />  ...
What does the below line do considering it as the first line in your...
Alert!

Advertisement