# JavaScript Language | 10 Minute‐Test 4

Instruction

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

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]

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)

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

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

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

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

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

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

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

Explanation:

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

##### Test 27

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