JavaScript Language | 30 Minute Test 1


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.

A JavaScript program developed on a Unix Machine

A.
will throw errors and exceptions
B.
must be restricted to a Unix Machine only
C.
will work perfectly well on a Windows Machine
D.
will be displayed as a JavaScript text on the browser

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None

2.

The generalised syntax for a real number representation is

A.
[digits][.digits][(E|e)[(+|-)]digits]
B.
[digits][+digits][(E|e)[(+|-)]digits]
C.
[digits][(E|e)[(+|-)]digits]
D.
[.digits][digits][(E|e)[(+|-)]digits]

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Floating-point literals may also be represented using exponential notation: a real number followed by the letter e (or E), followed by an optional plus or minus sign, followed by an integer exponent. This notation represents the real number multiplied by 10 to the power of the exponent.

3.

Consider the following statements

var text = "testing: 1, 2, 3"; // Sample text

var pattern = /\d+/g // Matches all instances of one or more digits


In order to check if the pattern matches with the string “text”, the statement is

A.
text==pattern
B.
text.equals(pattern)
C.
text.test(pattern)
D.
pattern.test(text)

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The given pattern is applied on the text given in the parenthesis.

4.

Which is a more efficient code snippet ?
Code 1 :

 for(var num=10;num>=1;num--)

{

 document.writeln(num);

}


Code 2 :

 var num=10;

while(num>=1)

{        

document.writeln(num);        

num--;

}

A.
Code 1
B.
Code 2
C.
Both Code 1 and Code 2
D.
Cannot Compare

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

A for loop is always more efficient because it encapsules two individual statements(initialization and expression) within the braces.

5.

Consider the following code snippet

for(var p in o)

   console.log(o[p]);


The above code is equivalent to which code?

A.
 for (var i = 0;i < a.length;i++)
console.log(a[i]);
B.
for (int i = 0;i < a.length;i++)
console.log(a[i]);
C.
for (var i = 0;i <= a.length;i++)
console.log(a[i]);
D.
for (var i = 1;i < a.length;i++)
console.log(a[i]);

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The for/in loop makes it easy to do the same that we do using a for.

6.

A linkage of series of prototype objects is called as :

A.
prototype stack
B.
prototype chain
C.
prototype class
D.
prototypes

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Consider an example, Date.prototype inherits properties from Object.prototype, so a Date object created by new Date() inherits properties from both Date.prototype and Object.prototype. This linked series of prototype objects is known as prototype chain.

7.

Consider the following code snippet :

if (!a[i]) continue;
What is the observation made ?

A.
Skips the undefined elements
B.
Skips the non existent elements
C.
Skips the null elements
D.
All of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None

8.

What is the purpose of a return statement in a function?

A.
Returns the value and continues executing rest of the statements, if any
B.
Returns the value and stops the program
C.
Returns the value and stops executing the function
D.
Stops executing the function and returns the value

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The return statement causes the function to stop executing and to return the value of its expression (if any) to the caller.

9.

Consider the following code snippet :

var string2Num=parseInt("123xyz");
The result for the above code snippet would be :

A.
123xyz
B.
123
C.
Exception
D.
NaN

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The parseInt() function returns the first integer contained in the string or 0 if the string does not begin with an integer.

10.

Which of the following are examples of closures?

A.
Objects
B.
Variables
C.
Functions
D.
All of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Technically, all JavaScript functions are closures: they are objects, and they have a scope chain associated with them.

11.

The basic difference between JavaScript and Java is

A.
There is no difference
B.
Functions are considered as fields
C.
Variables are specific
D.
functions are values, and there is no hard distinction between methods and fields

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The basic difference between JavaScript and Java is that the functions are values, and there is no hard distinction between methods and fields.

12.

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The variable properties are usually variables that are used internally in the objects methods, but can also be globally visible variables that are used through the page.

13.

The scope of a function is also called as

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The scope of a function can be used as a private namespace for a module. Therefore, the scope of a function is called a module function.

14.

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

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

We should always be careful while using * and ? as repetition characters as they may match zero instances of whatever precedes them, they are allowed to match nothing.

15.

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The Good Parts is a language subset designed for aesthetic reasons and with a desire to improve programmer productivity. There is a larger class of subsets that have been designed for the purpose of safely running untrusted JavaScript in a secure container or “sandbox”.

16.

Consider the following code snippet

function 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 if
oddsums(5);
is executed afted the above 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]

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The above code returns 1,4,9,16,25 which is the square of the first five natural numbers. Notice the usage of let keyword in the above code snippet.

17.

When will the finally block be called?

A.
When there is no exception
B.
When the catch doesnot match
C.
Both a and b
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

A finally block is called after try-catch execution.

18.

Which function is a synonym for on()?

A.
addListener()
B.
listeners()
C.
once()
D.
add()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The on() method is used for registering handlers. addListener() is a synonym for on().

19.

Which Rhino command quits Rhino environment?

A.
terminate()
B.
exit()
C.
quit()
D.
close()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The quit() command makes Rhino exit.

20.

What is the alternative command used in Node for load()?

A.
store()
B.
module()
C.
log()
D.
require()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Use require() instead of load(). It loads and executes (only once) the named module, returning an object that contains its exported symbols.

21.

Which object supports Filesystem API?

A.
Element
B.
File
C.
Window
D.
DOM

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The File object allows user-selected files to be uploaded through an XMLHttpRequest.

22.

Which is the root element in a HTML document?

A.
HTML
B.
HEAD
C.
SCRIPT
D.
BODY

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The "html" tag is the root element of any HTML document regardless of it containing a JavaScript code or not.

23.

Which property in the Window object is used to refer to a Location object?

A.
position
B.
area
C.
window
D.
location

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The Window object defines properties like location, which refers to a Location object that specifies the URL currently displayed in the window and allows a script to load a new URL into the window.

24.

What is the purpose of the event handlers in the JavaScript?

A.
Adds innerHTML page to the code
B.
Performs handling of exceptions and occurences
C.
Allows JavaScript code to alter the behaviour of windows
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Event handlers allow JavaScript code to alter the behavior of windows, of documents, and of the elements that make up those documents.

25.

What is the purpose of Dojo framework?

A.
Focuses on DOM and Ajax utilities
B.
Advertises incredible depth
C.
Both a and b
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Dojo is a large framework that advertises its “incredible depth.” It includes an extensive set of UI widgets, a package system, a data abstraction layer, and more.

26.

Which property is used to obtain browser vendor and version information?

A.
modal
B.
version
C.
browser
D.
navigator

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The navigator property is used to obtain browser vendor and version information.

27.

What is the return type of the hash property?

A.
Query string
B.
Packets
C.
String
D.
Fragment identifier

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The hash property returns the “fragment identifier” portion of the URL, if there is one: a hash mark (#) followed by an element ID.

28.

What is the datatype of the go() method’s parameter?

A.
String
B.
Integer
C.
Double
D.
Float

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The go() method takes an integer argument and can skip any number of pages forward and backward in the history list.

29.

What is the distinction made by JavaScript between windows, tabs, iframes, and frames ?

A.
They are all browsing contexts
B.
They are all browsing informations
C.
They are all Window contexts
D.
They are all Window objects

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Client-side JavaScript makes very little distinction between windows, tabs, iframes, and frames: they are all browsing contexts, and to JavaScript, they are all Window objects.

30.

The Text and Comment is part of

A.
CharacterData
B.
Document
C.
Attr
D.
Element

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The Text and Comment is part of the CharacterData Element.

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