Explore topic-wise MCQs in Javascript.

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

1.

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

A. mporting a single module
B. mporting a module partially
C. mporting a namespace
D. mporting the entire module
Answer» E.
2.

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

A. ext==pattern
B. ext.equals(pattern)
C. ext.test(pattern)
D. attern.test(text)
Answer» E.
3.

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

A. ort in the alphabetical order
B. ort in the chronological order
C. ort in reverse alphabetical order
D. ort in reverse numerical order
Answer» E.
4.

Consider the following code snippetlet succ = function(x) x+1, yes = function() true, no = function() false;What convenience does the above code snippet provide?

A. unctional behaviour
B. odular behaviour
C. o convenience
D. horthand expression
Answer» B. odular behaviour
5.

Consider the following code snippet[x,y]=[y,x];What is the result of the above code snippet?

A. hrows exception
B. wap the value of the two variables
C. lashes an error
D. reates a new reference object
Answer» D. reates a new reference object
6.

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

A. ero
B. ull
C. eferenceError
D. alueNotFoundError
Answer» D. alueNotFoundError
7.

Consider the following code snippetfunction oddsums(n){let total = 0, result=[];for(let x = 1; x <= n; x++){let odd = 2*x-1;total += odd;result.push(total);}return result;}What would be the output ifoddsums(5)is executed afted the above code snippet ?

A. eturns [1,4,9,16,25]
B. eturns [1,2,3,4,5]
C. eturns [3,6,9,12,15]
D. eturns [1,3,5,7,9]
Answer» B. eturns [1,2,3,4,5]
8.

Consider the following code snippetconst pi=3.14;var pi=4;console.log(pi);What will be the output for the above code snippet?

A. his will flash an error
B. rints 4
C. rints 3.14
D. mbiguity
Answer» B. rints 4
9.

Consider the following code snippet. What would be the output if oddsums(5); is executed afted the below code snippet ?

A. Returns [1,4,9,16,25]
B. Returns [1,2,3,4,5]
C. Returns [3,6,9,12,15]
D. Returns [1,3,5,7,9]
Answer» B. Returns [1,2,3,4,5]
10.

Consider the following statementvar 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
11.

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

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

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

Consider the following code snippet:let succ = function(x) x+1, yes = function() true, no = function() false;What convenience does the above code snippet provide?

A. Functional behaviour
B. Modular behaviour
C. No convenience
D. Shorthand expression
Answer» B. Modular behaviour
15.

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

Consider the following code snippet:[x,y]=[y,x];What is the result of the above code snippet?

A. Throws exception
B. Swap the value of the two variables
C. Flashes an error
D. Creates a new reference object
Answer» D. Creates a new reference object
17.

The "$" present in the RegExp object is called a

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

Consider the following code snippet: const pi=3.14;var pi=4;console.log(pi);What will be the output for the above code snippet?

A. This will flash an error
B. Prints 4
C. Prints 3.14
D. Ambiguity
Answer» B. Prints 4
19.

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

The let keyword can be used

A. in a for or for/in loop, as a substitute for var
B. as a block statement, to define new variables
C. to define variables that are scoped to a single expression
D. all of the mentioned
Answer» E.
21.

Consider the following code snippet :var o = new F();o.constructor === FThe output would be :

A. false
B. true
C. 0
D. 1
Answer» C. 0
22.

The Crockford's subset does not include which function in JavaScript?

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

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

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

Why is this keyword not preferred 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
25.

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. object doesn't inherit prototype properties in static state
Answer» B. objects inherit prototype properties only in dynamic state
26.

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

The different variant of Date() constructor to create date object is/arei. 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
Answer» C. i, ii and iv only
28.

If A is the superclass and B is the subclass, then subclass inheriting 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);
29.

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].
30.

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
Answer» C. Interfaces
31.

The '$' present in the RegExp object is called a ____________

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

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

A. declaring and loading modules
B. declaring functions
C. declaring modules
D. loading modules
Answer» B. declaring functions
33.

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

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

Which of the following is the descendant operator?%!

A. ..
B. …
C. *
D. @
Answer» C. *
36.

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

Which are the two functions that are not allowed in any secure subset?%!

A. evaluate() and restrict()
B. eval() and the Function() constructor
C. debugger() and test()
D. eval() and debugger()
Answer» C. debugger() and test()
38.

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

Consider the following code snippet[x,y]=[y,x];What is the result of the above code snippet?%!

A. Throws exception
B. Swap the value of the two variables
C. Flashes an error
D. Creates a new reference object
Answer» D. Creates a new reference object
40.

Consider the following code snippetdata.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.
41.

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

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

The class that represents the regular expressions is%!

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

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

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

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

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

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‚Äö√Ñ√π
47.

*$_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
48.

*$_Which are the two functions that are not allowed in any secure subset??

A. evaluate() and restrict()
B. eval() and the Function() constructor
C. debugger() and test()
D. eval() and debugger()
Answer» C. debugger() and test()
49.

*$_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
50.

*$_The class that represents the regular expressions is?

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