This article we are go to through some of the most expected javascript questions and answers to help you get going in job interviews and make a good impression with your knowledge.
This set of Top Ten Javascript Multiple Choice questions and answers (MCQs) focuses on “Classes in JavaScript”.
1. The behaviour of the instances present of a class inside a method is defined by
a. Method
b. Classes
c. Interfaces
d. Classes and Interfaces
Explanation : The behaviour of the instance of a class is defined by the class and is shared by all instances.
2. The keyword or the property that you use to refer to an object through which they were invoked is
a. from
b. to
c. this
d. object
Explanation : The ‘this’ keyword is used to refer to the object through which the properties or methods were invoked. This use of ‘this’ is a fundamental characteristic of the methods of any class.
3. Consider the following code snippet :
var o = new F(); o.constructor === F
The output would be :
a. false
b. true
c. 0
d. 1
Explanation : The result is true: the constructor property specifies the class.
4. If A is the superclass and B is the subclass, then subclass inherting the superclass can be represented as ?
a. B=inherit(A);
b. B=A.inherit();
c. B.prototype=inherit(A);
d. B.prototype=inherit(A.prototype);
Explanation : The subclass B inherits the prototype of the class A.
5. The meaning for Augmenting classes is that
a. objects inherit prototype properties even in dynamic state
b. objects inherit prototype properties only in dynamic state
c. objects inherit prototype properties in static state
d. None of the mentioned
Explanation : JavaScript’s prototype-based inheritance mechanism is dynamic: an object inherits properties from its prototype, even if the prototype changes after the object is created. This means that we can augment JavaScript classes simply by adding new methods to their prototype objects.
6. The property of JSON() method is?
a. it can be invoked manually as object.JSON()
b. it will be automatically invoked by the compiler
c. it is invoked automatically by the JSON.stringify() method
d. it cannot be invoked in any form
Explanation : The JSON format is intended for serialization of data structures and can handle JavaScript primitive values, arrays, and plain objects. It does not know about classes, and when serializing an object, it ignores the object’s prototype and constructor. If you call JSON.stringify() on a Range or Complex object, for example, it returns a string like {“from”:1, “to”:3} or {“r”:1, “i”:-1}.
7. When a class B can extend another class A, we say that
a. A is the superclass and B is the subclass
b. B is the superclass and A is the subclass
c. Both A and B are the superclass
d. Both A and B are the subclass
Explanation : Instances of B inherit all the instance methods of A. The class B can define its own instance methods, some of which may override methods of the same name defined by class A.
4. The basic difference between JavaScript and Java is ?
a. There is no difference
b. Functions are considered as fields
c. Variables are specific
d. functions are values, and there is no hard distinction between methods and fields
Explanation : The basic difference between JavaScript and Java is that the functions are values, and there is no hard distinction between methods and fields.
9. The snippet that filters the filtered set is
a. var t=new FilteredSet(s, {function(s) {return !(x instanceof Set);});
b. var t=new FilteredSet{function(s) {return !(x instanceof Set);});
c. var t=new FilteredSet(s, {function(s) {return (x instanceof Set);});
d. var t=new FilteredSet(s, {function(s) {return x;});
Explanation : None
10. The method that can be used to create new properties and also to modify the attributes of existing properties is ?
a. Object.defineProperty()
b. Object.defineProperties()
c. Both a and b
d. None of the mentioned
Explanation : When used to define new properties, any attributes you omit default to false. Therefore, both Object.defineProperty() and Object.defineProperties() can be used to create and modify the attributes.
So, what other JavaScript questions are there about Scripting Java with Rhino?If you liked this Javascript MCQ, share, recommend or like below!