This set of Top ten Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Augmentation of Classes”.
1. The four kinds of class members are ?
a. Instance methods, Instance fields, Static method, Dynamic method
b. Instance fields, Instance methods, Class fields, Class methods
c. Instance fields, Non-instance fields, Dynamic methods, Global methods
d. Global methods, Local methods, Dynamic methods, Static methods
Explanation : The four kinds of class members are Instance fields, Instance methods, Class fields, Class methods.
2. The properties of the objects act like different kinds of class members. They are ?
a. Public object, Private object, Protected object
b. Constructor object, Function object, Destructor object
c. Constructor object, Prototype object, Instance object
d. Instance method, Static object, Dynamic object
Explanation : In JavaScript, there are three different objects involved inany class definition, and the properties of these three objects act like different kinds of class members namely, Constructor object, Prototype object, and Instance object.
3. The object whose properties are inherited by all instances of the class, and properties whose values are functions behaving like instance methods of the class, is ?
a. Instance object
b. Constructor object
c. Destructor object
d. Prototype object
Explanation : The properties of the prototype object are inhertied by all instances of the class, and properties whose values are functions behave like instance methods of the class.
4. Which are usually variables that are used internally in object methods and also are globally visible variables?
a. Object properties
b. Variable properties
c. Method properties
d. Internal properties
Explanation : The variable properties are usually variables that are used internally in the objects methods, but can also be globally visible variables that are used through the page.
5. The class that represents the regular expressions is ?
a. RegExpObj
b. RegExpClass
c. RegExp
d. StringExp
Explanation : The JavaScript RegExp class represents regular expressions, and both string and RegExp define methods that use regular expressions.
6. The different variant of Date() constructor to create date object is/are ?
i. new Date(date)
ii. new Date(milliseconds)
iii. new Date(date string)
iv. new Date(year, month, date[, hour, minute, second, millisecond])
a. i, ii and iii only
b. ii, iii and iv only
c. i, ii and iv only
d. All i, ii, iii and iv
Explanation : The Date() consturctore appears in three different ways as mentioned above.
7. Which is the correct code that returns a complex number that is the complex conjugate of this one?
a. Complex.prototype.conj = function() { return new Complex(this.r, -this.i); };
b. Complex.prototype.conj = function() { return Complex(this.r, -this.i); };
c. Complex.prototype.conj = function() { return (this.r, -this.i); };
d. Complex.prototype.conj = function() { new Complex(this.r, -this.i); };
Explanation : The above code snippet returns a complex number that is the complex conjugate of this one.
8. How can we make methods available on all objects?
a. Object.add(methods)
b. Object.methods(add)
c. Object.add.methods(…)
d. Object.prototype
Explanation : It is possible to add methods to Object.prototype, making them available on all objects. This is not recommended, however, because prior to ECMAScript5, there is no way to make these add-on methods nonenumerable, and if you add properties to Object.prototype, those properties will be reported by all for/in loops.
9. What is the procedure to add methods to HTMLElement so that they will be inherited by the objects that represent the HTML tags in the current document?
a. HTMLElement.prototype(…)
b. HTMLElement.prototype
c. HTML.addmethods()
d. HTML.elements(add)
Explanation : It is implementation-dependent whether classes defined by the host environment (such as the web browser) can be augmented using Object.prototype. In many web browsers, for example, you can add methods to HTMLElement.prototype and those methods will be inherited by the objects that represent the HTML tags in the current document.
10. You can refresh the webpage in JavaScript by using?
a. window.reload
b. location.reload
c. window.refresh
d. page.refresh
Explanation : One can refresh the webpage in JavaScript by using location.reload.
So, what other JavaScript questions are there about Augmentation of Classes?If you liked this Javascript MCQ, share, recommend or like below!