JavaScript Language | 20 Minute‐Test 2


Instruction

  • Total number of questions : 20.
  • Time alloted : 20 minutes.
  • Each question carry 1 mark.
  • No Negative marks
  • DO NOT refresh the page.
  • All the best :-).

1.

JavaScript can be written

A.
directly into JS file and included into HTML
B.
directly on the server page
C.
directly into HTML pages
D.
All of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None

2.

The snippet that has to be used to check if “a” is not equal to “null” is

A.
if(a!=null)
B.
if (!a)
C.
if(a!null)
D.
if(a!==null)

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The not-equal operator !== compares o to null and evaluates to either true or false.

3.

Among the following, which one is a ternary operator?

A.
+
B.
:
C.
D.
?:

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

JavaScript supports one ternary operator, the conditional operator ?:, which combines three expressions into a single expression.

4.

Consider the following statements

switch(expression)

{

    statements

}


In the above switch syntax, the expression is compared with the case labels using which of the following operator(s) ?

A.
==
B.
equals
C.
equal
D.
===

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

When a switch executes, it computes the value of expression and then looks for a case label whose expression evaluates to the same value (where sameness is determined by the === operator).

5.

Consider the following code snippet

while (a != 0)

{

   if (a == 1)

       continue;

   else

       a++;

}


What will be the role of the continue keyword in the above code snippet?

A.
The continue keyword restarts the loop
B.
The continue keyword skips the next iteration
C.
The continue keyword skips the rest of the statements in that iteration
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Instead of exiting a loop like the break keyword, the continue keyword moves to the next iteration from the place encountered.

6.

The purpose of extensible attribute is to

A.
make all of the own properties of that object nonconfigurable
B.
to configure and bring a writable property
C.
“lock down” objects into a known state and prevent outside tampering
D.
All of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The purpose of the extensible attribute is to be able to “lock down” objects into a known state and prevent outside tampering.

7.

The primary purpose of the array map() function is that it

A.
maps the elements of another array into itself
B.
passes each element of the array and returns the necessary mapped elements
C.
passes each element of the array on which it is invoked to the function you specify, and returns an array containing the values returned by that function.
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The map() method passes each element of the array on which it is invoked to the functionyou specify, and returns an array containing the values returned by that function.

8.

Which of the following is the correct code for invoking a function without this keyword at all, and also too determine whether the strict mode is in effect?

A.
var strict = (function { return this; });
B.
mode strict = (function() { return !this; }());
C.
var strict = (function() { return !this; }());
D.
mode strict = (function { });

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The above code defines and invokes a function to determine if we’re in strict mode.

9.

What is the difference between the two lines given below ?

!!(obj1 && obj2);
(obj1 && obj2);

A.
Both the lines result in a boolean value “True”
B.
Both the lines result in a boolean value “False”
C.
Both the lines checks just for the existence of the object alone
D.
The first line results in a real boolean value whereas the second line merely checks for the existence of the objects

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

10.

What is the opposite approach to the lexical scoping?

A.
Literal scoping
B.
Static scoping
C.
Dynamic scoping
D.
Generic scoping

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The opposite approach to the lexical scoping is the dynamic scoping.

11.

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

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The subclass B inherits the prototype of the class A.

12.

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)

Your Answer: Option (Not Answered)

Correct Answer: Option B

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.

13.

The properties() method is a

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The properties() method is a non-enumerable method.

14.

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

A.
searchandreplace()
B.
add()
C.
edit()
D.
replace()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The replace() method performs a search-and-replace operation. It takes a regular expression as its first argument and a replacement string as its second argument.

15.

Which is the object that defines methods that allow complete control over page content?

A.
The client-side document object
B.
The server-side document object
C.
Both a and b
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The client-side document object defines methods that allow complete control over page content.

16.

Which looping statement allows XML tags to appear in JavaScript programs and adds API for operating on XML data?

A.
for loop
B.
while loop
C.
for/each loop
D.
All of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The for/each loop is a new looping statement standardized by E4X. E4X (ECMAScript for XML) is a language extension that allows XML tags to appear literally in JavaScript programs and adds syntax and API for operating on XML data.

17.

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(…)

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

E4X is designed so that you can perform most common XML manipulations using language syntax. E4X also defines methods you can invoke on XML objects. Here, for example, is the insertChildBefore() method:

pt.insertChildBefore(pt.element[1],<element id="1"><name>Deuterium</name></element>);

18.

What is the method used to pause “data” events?

A.
s.pause();
B.
s.stop();
C.
s.halt();
D.
s.wait();

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The above code snippet is used to pause data events, for throttling uploads, e.g.

19.

What does Rhino do when the getter and setter methods exist?

A.
It becomes JavaScript properties
B.
Java classes are used to avoid them
C.
Both a and b
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Rhino allows JavaScript code to query and set the static fields of Java classes and the instance fields of Java objects. Java classes often avoid defining public fields in favor of getter and setter methods. When getter and setter methods exist, Rhino exposes them as JavaScript properties.

20.

Why does Node not block while waiting for operations to complete?

A.
Static
B.
Asynchronous
C.
Synchronous
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Because Node’s functions and methods are asynchronous, they do not block while waiting for operations to complete.

Submit your test now to view the Results and Statistics with answer explanation.