JavaScript Language | 30 Minute Test 5


Instruction

  • Total number of questions : 30.
  • Time alloted : 30 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.

21.

What is the lifetime of the data stored through localStorage?

A.
Permanant
B.
Temporary
C.
Both a and b at times
D.
Cannot store

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Data stored through localStorage is permanent: it does not expire and remains stored on the user’s computer until a web app deletes it or the user asks the browser (through some browser-specific UI) to delete it.

22.

What will be done if more than one page requires a file of JavaScript code?

A.
Downloads that many times
B.
Retrives from the browser cache
C.
Must be re executed
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

If a file of JavaScript code is shared by more than one page, it only needs to be downloaded once, by the first page that uses it—subsequent pages can retrieve it from the browser cache.

23.

When will the window property come into play?

A.
Representation convenience
B.
Use as an extension of other objects
C.
Use objects in the Window object
D.
Refer to window object itself

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The Window object has a property named window that always refers to itself. You can use this property if you need to refer to the window object itself, but it is not usually necessary to use window if you just want to refer to access properties of the global window object.

24.

What is the code snippet to change the class and let the stylesheet specify the details?

A.
timestamp.className = "highlight";
B.
timestamp.className = "change";
C.
timestamp.className = "specify";
D.
timestamp.className = "move";

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The above code snippet changes the class and lets the stylesheet specify the details.

25.

Which of the following framework was used by Google for Gmail?

A.
Dojo
B.
GWT
C.
YUI
D.
Closure

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The Closure library is the client-side library that Google uses for Gmail, Google Docs, and other web applications. This library is intended to be used with the Closure compiler, which strips out unused library functions.

26.

What will happen if we call setTimeout() with a time of 0 ms?

A.
Placed in stack
B.
Placed in queue
C.
Will run continuously
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

If you call setTimeout() with a time of 0 ms, the function you specify is not invoked right away. Instead, it is placed on a queue to be invoked “as soon as possible” after any currently pending event handlers finish running.

27.

Why is the replace() method better than the assign() method?

A.
Reliable
B.
Highly managable
C.
More efficient
D.
Handles unconditional loading

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The replace() method is similar, but it removes the current document from the browsing history before loading the new document. When a script unconditionally loads a new document, the replace() method is often a better choice than assign().

28.

Which is the preferred testing nowadays for scripting?

A.
Software testing
B.
Feature testing
C.
Blackbox testing
D.
Whitebox testing

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

In the past, the Navigator object was commonly used by scripts to determine if they were running in Internet Explorer or Netscape. This “browser-sniffing” approach is problematic because it requires constant tweaking as new browsers and new versions of existing browsers are introduced. Today, feature testing is preferred: rather than making assumptions about particular browser versions and their features, you simply test for the feature (i.e., the method or property) you need.

29.

Which is the property of a Window object that holids the name of the frame?

A.
name
B.
title
C.
description
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The name property of a Window object holds the name of the frame, if it has one. This property is writable, and scripts can set it as desired.

30.

Which of the following can be used to select HTML elements based on the value of their name attributes?

A.
getElementByName()
B.
getElementsByName()
C.
getElementsName()
D.
getElementName()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

To select HTML elements based on the value of their name attributes, you can use the getElementsByName() method of the Document object:

var radiobuttons = document.getElementsByName("favorite_color");

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