Explore topic-wise MCQs in Javascript.

This section includes 302 Mcqs, each offering curated multiple-choice questions to sharpen your Javascript knowledge and support exam preparation. Choose a topic below to get started.

101.

Which event can be fired on any scrollable document element?

A. Window
B. Scroll
C. Load
D. Unload
Answer» C. Load
102.

Which is the property that is triggered in response to JavaScript errors?

A. onexception
B. onmessage
C. onerror
D. none of the mentioned
Answer» D. none of the mentioned
103.

The client-side JavaScript’s asynchronous programming model contains

A. Timers and error handlers
B. User interface events
C. State change events
D. API-specific events
Answer» B. User interface events
104.

The video and the audio belong to the

A. Timers and error handlers
B. API-Specific events
C. State change events
D. User interface events
Answer» C. State change events
105.

The events that are not directly tied to a specific input device are

A. User interface events
B. Device-independent events
C. Device-dependent events
D. All of the mentioned
Answer» C. Device-dependent events
106.

The high-level events among the following events are

A. User interface events
B. Device-independent events
C. Device-dependent events
D. All of the mentioned
Answer» B. Device-independent events
107.

The events that are directly tied to a specific input device are

A. Device-independent input events
B. Device-dependent input events
C. User interface events
D. State change events
Answer» C. User interface events
108.

In general, event handler is nothing but

A. function
B. interface
C. event
D. handler
Answer» B. interface
109.

What is the code required to delete all “weight” tags?

A. delete weight(pt).all;
B. delete pt.element[all];
C. delete pt;
D. delete pt..weight;
Answer» E.
110.

Which of the following is an example to perform the most common XML manipulations using the XML objects invocation?

A. insertChildBefore()
B. insertChildAfter()
C. appendChildAfter(…)
D. appendChildBefore(…)
Answer» B. insertChildAfter()
111.

Which of the following is the descendant operator?

A. ..
B.
C. *
D. @
Answer» C. *
112.

Which method to use while working with XML fragments, instead of XML()?

A. XMLInterface()
B. XMLClass()
C. XMLList()
D. XMLArray()
Answer» D. XMLArray()
113.

What is the return type of typeof for standard JavaScript objects?

A. xml
B. object
C. dom
D. html
Answer» C. dom
114.

When will the finally block be called?

A. When there is no exception
B. When the catch doesnot match
C. When there is exception
D. None of the mentioned
Answer» E.
115.

Consider the following code snippet data.sort(function(a,b),b-a); What does the above code do?

A. Sort in the alphabetical order
B. Sort in the chronological order
C. Sort in reverse alphabetical order
D. Sort in reverse numerical order
Answer» E.
116.

Which method of the iterable object returns an iterator object for the collection?

A. iterator()
B. _iterator_()
C. _iteration_()
D. _return_iterator_()
Answer» C. _iteration_()
117.

Consider the following code snippet let x=x+1; console.log(x); What will be the result for the above code snippet?

A. 0
B. Null
C. ReferenceError
D.
Answer» E.
118.

Consider the following code snippet console.log(p) If p is not defined, what would be the result or type of error?

A. Zero
B. Null
C. ReferenceError
D. ValueNotFoundError
Answer» D. ValueNotFoundError
119.

Which is the subset that transforms web content into secure modules that can be safely hosted on a web page?

A. Microsoft Web Sandbox
B. ADsafe
C. Caja
D. dojox.secure
Answer» E.
120.

Why is the this keyword forbidden in JavaScript?

A. Highly memory consuming
B. Functions should access the global objects
C. Functions should not access the global objects
D. Very inefficient to use
Answer» D. Very inefficient to use
121.

Why was “The Good Parts” designed as a language subset in JavaScript?

A. To improve programmer flexibility
B. To balance the work load of the programmer
C. To create an in-built compiler and interpreter
D. To improve programmer productivity
Answer» E.
122.

Why does JavaScript subset disallow == and !=?

A. It uses bitwise checking
B. It uses === and !== instead
C. It uses equals() and notequals() instead
D. None of the mentioned
Answer» C. It uses equals() and notequals() instead
123.

The Crockford’s subset doesnot include which function in JavaScript?

A. eval()
B. coeval()
C. equal()
D. equivalent()
Answer» B. coeval()
124.

What would be the result of the following statement in JavaScript using regular expression methods ?

A. Returns [“123″”456″”789”]
B. Returns [“123″,”456″,”789”]
C. Returns [1,2,3,4,5,6,7,8,9]
D. Throws an exception
Answer» C. Returns [1,2,3,4,5,6,7,8,9]
125.

The method that performs the search-and-replace operation to strings for pattern matching is

A. searchandreplace()
B. add()
C. edit()
D. replace()
Answer» C. edit()
126.

What does the subexpression /java(script)?/ result in ?

A. It matches “java” followed by the optional “script”
B. It matches “java” followed by any number of “script”
C. It matches “java” followed by a minimum of one “script”
D. None of the mentioned
Answer» B. It matches “java” followed by any number of “script”
127.

What will be the result when non greedy repetition is used on the pattern /a+?b/ ?

A. Matches the letter b preceded by the fewest number of a’s possible
B. Matches the letter b preceded by any number of a
C. Matches letter a preceded by letter b, in the stack order
D. None of the mentioned
Answer» B. Matches the letter b preceded by any number of a
128.

What does /[^(]* regular expression indicate ?

A. Match one or more characters that are not open paranthesis
B. Match zero or more characters that are open paranthesis
C. Match zero or more characters that are not open paranthesis
D. Match one or more characters that are open paranthesis
Answer» D. Match one or more characters that are open paranthesis
129.

The regular expression to match any one character not between the brackets is

A. […]
B. [^]
C. [^…]
D. [D]
Answer» D. [D]
130.

Consider the following statement containing regular expressions var text = "testing: 1, 2, 3"; var pattern = /d+/g; In order to check if the pattern matches, the statement is

A. text==pattern
B. text.equals(pattern)
C. text.test(pattern)
D. pattern.test(text)
Answer» E.
131.

The ‘$’ present in the RegExp object is called a

A. character
B. matcher
C. metacharacter
D. metadata
Answer» D. metadata
132.

What can be done in order to avoid creation of global variables in JavaScript?

A. To use a method that defines all the variables
B. To use an object that has the reference to all the variables
C. To use an object as its namespace
D. To use global functions
Answer» D. To use global functions
133.

The properties() method is a

A. Enumerable method
B. Non-enumerable method
C. Operational method
D. None of the mentioned
Answer» C. Operational method
134.

Consider the following code snippet var sets = com.davidflanagan.collections.sets; What is the programmer trying to do in the above code snippet?

A. Importing a single module
B. Importing a module partially
C. Importing a namespace
D. Importing the entire module
Answer» E.
135.

Modules that have more than one item in their API can

A. Assign itself to a global variable
B. Invoke another module of the same kind
C. Return a namespace object
D. Invoke another module of the same kind
Answer» D. Invoke another module of the same kind
136.

The scope of a function is also called as

A. The function’s scope
B. Module function
C. Modulated function
D. Private function
Answer» C. Modulated function
137.

Consider the following statement var Set = sets.Set; var s = new Set(1,2,3); What could be the efficiency quotient of the above two statements ?

A. The programmer imports at once the frequently used values into the global namespace
B. There is no efficiency quotient, the programmer tries to make it inefficient
C. The programmer needs to import the Sets everytime he wants to use it
D. All of the mentioned
Answer» B. There is no efficiency quotient, the programmer tries to make it inefficient
138.

To define each of the set classes as a property of the sets object (namespace) for the module, the statement is

A. sets = sets.AbstractEnumerableSet.extend();
B. sets.SingletonSet = sets.AbstractEnumerableSet.extend(...);
C. sets.SingletonSet = sets.extend(...);
D. sets = sets.extend(...);
Answer» C. sets.SingletonSet = sets.extend(...);
139.

The functions provide() and require() of Dojo toolkit and Google’s Closure library are used for

A. declaring and loading modules
B. loading and declaring modules
C. declaring modules
D. none of the mentioned
Answer» B. loading and declaring modules
140.

You can refresh the webpage in JavaScript by using

A. window.reload
B. location.reload
C. window.refresh
D. page.refresh
Answer» C. window.refresh
141.

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)
Answer» C. HTML.addmethods()
142.

How can we make methods available on all objects?

A. Object.add(methods)
B. Object.methods(add)
C. Object.add.methods(…)
D. Object.prototype
Answer» E.
143.

The class that represents the regular expressions is

A. RegExpObj
B. RegExpClass
C. RegExp
D. StringExp
Answer» D. StringExp
144.

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
Answer» C. Method properties
145.

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
Answer» D. Instance method, Static object, Dynamic object
146.

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 Object.defineProperty() and Object.defineProperties()
D. None of the mentioned
Answer» D. None of the mentioned
147.

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;});
Answer» B. var t=new FilteredSet{function(s) {return !(x instanceof Set);});
148.

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);
Answer» D. B.prototype=inherit(A.prototype);
149.

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
Answer» B. B is the superclass and A is the subclass
150.

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
Answer» B. objects inherit prototype properties only in dynamic state