JavaScript Language | 30 Minute Test 3


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.

Which attribute is used to specify that the script is executed when the page has finished parsing ( only for external scripts )

A.
parse
B.
async
C.
defer
D.
type

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

In order to load a page, the browser must parse the contents of all script tags, which adds additional time to the page load. By minimizing the amount of JavaScript needed to render the page, and deferring parsing of unneeded JavaScript until it needs to be executed, you can reduce the initial load time of your page.

2.

Which of the following is not considered as an error in JavaScript?

A.
Syntax error
B.
Missing of semicolons
C.
Division by zero
D.
All of the above

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Division by zero is not an error in JavaScript: it simply returns infinity or negative infinity. There is one exception, however: zero divided by zero does not have a welldefined value, and the result of this operation is the special not-a-number value, printed as NaN.

3.

What kind of an expression is “new Point(2,3)”?

A.
Primary Expression
B.
Object Creation Expression
C.
Invocation Expression
D.
Constructor Calling Expression

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

An object creation expression creates a new object and invokes a function (called a constructor) to initialize the properties of that object. Object creation expressions are like invocation expressions except that they are prefixed with the keyword new.

4.

When an empty statement is encountered, a JavaScript interpreter

A.
Ignores the statement
B.
Prompts to complete the statement
C.
Throws an error
D.
Throws an exception

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The JavaScript interpreter takes no action when it executes an empty statement. The empty statement is occasionally useful when you want to create a loop that has an empty body.

5.

What will happen if the body of a for/in loop deletes a property that has not yet been enumerated?

A.
The property will be stored in a cache
B.
The loop will not run
C.
That property will not be enumerated
D.
All of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

If the body of a for/in loop deletes a property that has not yet been enumerated, that property will not be enumerated. If the body of the loop defines new properties on the object, those properties will generally not be enumerated.

6.

To determine whether one object is the prototype of (or is part of the prototype chain of) another object, one should use the

A.
isPrototypeOf() method
B.
equals() method
C.
=== operator
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

To determine whether one object is the prototype of (or is part of the prototype chain of) another object, one should use the isPrototype() method. To find out if p is the prototype of o write p.isPrototypeOf(o).

7.

Consider the following code snippet :

var a = [1,2,3,4,5];

a.slice(0,3);


What is the possible output for the above code snippet ?

A.
Returns [1,2,3]
B.
Returns [4,5]
C.
Returns [1,2,3,4]
D.
Returns [1,2,3,4,5]

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None

8.

A function with no return value is called

A.
Procedures
B.
Method
C.
Static function
D.
Dynamic function

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Functions with no return value are sometimes called procedures.

9.

If you have a function f and an object o, you can define a method named m of o with

A.
o.m=m.f;
B.
o.m=f;
C.
o=f.m;
D.
o=f;

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

method is nothing more than a JavaScript function that is stored in a property of an object. If you have a function f and an object o, you can define a method named m of o with the following line:
o.m = f;

10.

Consider the following code snippet :

var scope = "global scope";

function checkscope() {

var scope = "local scope";

function f()

{

     return scope;

}

return f;


What is the function of the above code snippet?

A.
Returns value null
B.
Returns exception
C.
Returns the value in scope
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

he above code snippet returns the value in scope.

11.

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

Your Answer: Option (Not Answered)

Correct Answer: Option C

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

12.

The different variant of Date() constructor to create date object is/are
i. 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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The Date() consturctore appears in three different ways as mentioned above.

13.

The provides() function and the exportsobject are used to

A.
Register the module’s API and Store their API
B.
Store the module’s API and register their API
C.
Both a and b
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Frameworks that define module loading systems may have other methods of exporting a module’s API. There may be a provides() function for modules to register their API, or an exports object into which modules must store their API.

14.

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The subexpression /java(script)?/ matches “java” followed by the optional “script”.

15.

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

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The this keyword is forbidden or restricted because functions (in non-strict mode) can access the global object through this. Preventing access to the global object is one of the key purposes of any sandboxing system.

16.

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Since x is a let variable and since x is undefined, so x+1 is NaN. Thus, the above code snippet prints NaN.

17.

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

A.
XMLInterface()
B.
XMLClass()
C.
XMLList()
D.
XMLArray()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

When working with XML fragments, use XMLList() instead of XML():

pt.element += new XMLList('<element id="6"><name>Carbon</name></element>'+'<element id="7"><name>Nitrogen</name></element>');

18.

When do uncaught exceptions generate events?

A.
When handlers are registered
B.
When handlers are deregistered
C.
When handler functions are called
D.
When handlers do not have a matching catch clause

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Uncaught exceptions generate events, if any handlers are registered. Otherwise, the exception just makes Node print an error and exit.

process.on("uncaughtException", function(e) { console.log(Exception, e); });

19.

Which is a more formal way of importing packages and classes as JavaScript objects?

A.
import(java.util.*);
B.
importClass(java.util.*);
C.
import.Class(java.util.*);
D.
Class.import(java.util.*);

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Because packages and classes are represented as JavaScript objects, you can assign themto

importClass(java.util.HashMap); // Same as : var HashMap = java.util.HashMap

variables to give them shorter names. But you can also more formally import them, if you want to:

20.

Among the below given functions, Node supports which of the following client-side timer functions?

A.
getInterval()
B.
Interval()
C.
clearTime()
D.
clearTimeout()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Node supports the client-side timer functions set setTimeout(), setInterval(), clearTimeout(), and clearInterval().

21.

The localStorage and sessionStorage belongs to

A.
Window object
B.
Element object
C.
Hash object
D.
DOM object

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Browsers that implement the “Web Storage” draft specification define two properties on the Window object: localStorage and sessionStorage. Both properties refer to a Storage object—a persistent associative array that maps string keys to string values.

22.

What is the code to start displaying the time when document loads?

A.
onload = displayTime;
B.
window. = displayTime;
C.
window.onload = displayTime; 
D.
window.onload = start;

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The above code starts displaying the time when the document loads.

23.

The setTimeout() method is used to

A.
Make the event sleep
B.
Register a function to be invoked after a certain time
C.
Invoke an event after a certain time
D.
Time for iteration

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The setTimeout(), which registers a function to be invoked after a specified amount of time.

24.

When a program contains extensive use of event handlers, which of the following is necessary?

A.
Modular functions
B.
Nested functions
C.
Split up programs
D.
All of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Nested functions are common in client-side JavaScript, because of its extensive use of event handlers.

25.

What does Dojo and YUI have in common?

A.
Facilitates DOM utilities and UI Widgets
B.
Doesnot facilitates DOM utilities and UI Widgets
C.
Client-side library
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Like Dojo, it is a large, all-encompassing library with language utilities, DOM utilities, UI widgets, and so on. There are actually two incompatible versions of YUI, known as YUI 2 and YUI 3.

26.

The setTimeout() belongs to which object?

A.
Element
B.
Window
C.
Location
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The setTimeout() method of the Window object schedules a function to run after a specified number of milliseconds elapses.

27.

The decodeURIComponent() is defined by

A.
Server-side JavaScript
B.
Client-side JavaScript
C.
Both a and b
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The decodeURIComponent() is a global function defined by client-side JavaScript.

28.

The navigator property belongs to which of the following object?

A.
Document
B.
Window
C.
Navigator
D.
Location

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The navigator property of a Window object refers to a Navigator object that contains browser vendor and version number information.

29.

What will happen if the first argument of open() is omitted?

A.
Error Page
B.
about:blank
C.
Remains in the same page
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

When the first argument of the open() is omitted, the about:blank is opened.

30.

Which of the following is/are of Text nodes?

A.
Text
B.
Comment
C.
Both a and b
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Both Text and Comment are basically strings of text, and these nodes are much like the Text nodes that represent the displaying text of a document.

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