# JavaScript Language | 20 Minute‐Test 7

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.

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.

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

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

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

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

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

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]

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

Explanation:

A finally block is called after try-catch execution.

18.

Which function is a synonym for on()?

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

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

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