64). What will be the output of the following JavaScript code?
function printArray(a)
{
var len = a.length, i = 0;
if (len == 0)
console.log("Empty Array");
else
{
do
{
console.log(a[i]);
} while (++i < len);
}
}
[A]Prints the numbers in the array in order
[B] Prints the numbers in the array in the reverse order
[C]Prints 0 to the length of the array
[D]Prints “Empty Array”
Show Answer
Correct Answer: Prints the numbers in the array in order
Notes:
Answer: a
Explanation: The do/while statement creates a loop that executes a block of code once, before checking if the condition is true, then it will repeat the loop as long as the condition is true. Hence the iterator traverses through the array and print them in normal order.
65). What are the three important manipulations done in a for loop on a loop variable?
function printArray(a)
{
var len = a.length, i = 0;
if (len == 0)
console.log("Empty Array");
else
{
do
{
console.log(a[i]);
} while (++i < len);
}
}
[A]Updation, Incrementation, Initialization
[B]Initialization,Testing, Updation
[C] Testing, Updation, Testing
[D]Initialization,Testing, Incrementation
Show Answer
Correct Answer: Initialization,Testing, Updation
Notes:
Answer: b
Explanation: In a for loop, the initialization, the test, and the update are the three crucial manipulations of a loop variable. Firstly the loop initialiases the variable then test the condition and then after executing the statement increments its value.
66). What will the following JavaScript code snippet work? If not, what will be the error?
function tail(o)
{
for (; o.next; o = o.next) ;
return o;
}
[A] No, this will throw an exception as only numerics can be used in a for loop
[B]No, this will not iterate
[C]Yes, this will work
[D]No, this will result in a runtime error with the message “Cannot use Linked List”
Show Answer
Correct Answer: Yes, this will work
Notes:
Answer: c
Explanation: The above code uses a for loop to traverse a linked list data structure and return the last object in the list. This will perfectly work.
67). What will be the equivalent code of the following JavaScript code?
for(var p in o)
console.log(o[p]);
[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 = 0;i <= a.length;i++) console.log(a[i]);
Show Answer
Correct Answer: for (var i = 0;i < a.length;i++) console.log(a[i]);
Notes:
Answer: a
Explanation: The in variable does the same task of traversing the array starting from the 0 index. The for/in loop makes it easy to do the same that we do using a for.
68). One of the special features of an interpreter in reference with the for loop is that ___________
for(var p in o)
console.log(o[p]);
[A]Before each iteration, the interpreter evaluates the variable expression and assigns the name of the property
[B]The iterations can be infinite when an interpreter is used
[C]The body of the loop is executed only once
[D] the iteration is finite when an interpreter is used
Show Answer
Correct Answer: Before each iteration, the interpreter evaluates the variable expression and assigns the name of the property
Notes:
Answer: a
Explanation: Interpreter translates the source code into machine code line by line, and stops when it encounters an error. Before each iteration, the interpreter evaluates the variable expression and assigns the name of the property (a string value) to it.
69). What will happen if the body of a for/in loop deletes a property that has not yet been enumerated?
for(var p in o)
console.log(o[p]);
[A]The property will be stored in a cache
[B]The loop will not run
[C] That property will not be enumerated
[D]The property will be enumerated
Show Answer
Correct Answer: That property will not be enumerated
Notes:
Answer: 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.
70). What will be the step of the interpreter in a jump statement when an exception is thrown?
for(var p in o)
console.log(o[p]);
[A]The interpreter stops its work
[B]The interpreter throws another exception
[C]The interpreter jumps to the nearest enclosing exception handler
[D]The interpreter throws an error
Show Answer
Correct Answer: The interpreter jumps to the nearest enclosing exception handler
Notes:
Answer: c
Explanation: When an exception is thrown in a jump statement, the interpreter jumps to the nearest enclosing exception handler, which may be in the same function or up the call stack in an invoking function.
71). What will be the role of the continue keyword in the following JavaScript code snippet?
while (a != 0)
{
if (a == 1)
continue;
else
a++;
}
[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]The continue keyword breaks out of the loop
Show Answer
Correct Answer: The continue keyword skips the rest of the statements in that iteration
Notes:
Answer: c
Explanation: Instead of exiting a loop like the break keyword, the continue keyword moves to the next iteration from the place encountered. While the break statement breaks out of the loop.
72). https://speedostream.bond/o0xox32iiuhz
function f(o)
{
if (o === undefined) debugger;
}
[A]It does nothing but a simple breakpoint
[B]It debugs the error in that statement and restarts the statement's execution
[C]It is used as a keyword that debugs the entire program at once
[D]It is used to find error in the statement
Show Answer
Correct Answer: It does nothing but a simple breakpoint
Notes:
Answer: a
Explanation: The debugger statement normally does nothing. If, however, a debugger program is available and is running, then an implementation may (but is not required to) perform some kind of debugging action. In practice, this statement acts like a breakpoint: execution of JavaScript code stops and you can use the debugger to print variable's values.
73). Among the keywords below, which one is not a statement?
function f(o)
{
if (o === undefined) debugger;
}
[A]debugger
[B]with
[C]if
[D]use strict
Show Answer
Correct Answer: use strict
Notes:
Answer: d
Explanation: use strict is a directive introduced in ECMAScript5. Directives are not statements because it does not include any language keywords. Also, it can appear only at the start of a script or at the start of a function body, before any real statement has appeared.
74). What will be the output of the following JavaScript code?
function range(int length)
{
int a=5;
for(int i=0;i
[A]5
[B]555
[C]3
[D]error
Show Answer
Correct Answer: 555
Notes:
Answer: b
Explanation: for loop first initializes the variable and later on checks for the condition expression and after that execute the line of statements. The value of iterator i increase until it reaches the value of length.
75). What will be the output of the following JavaScript code?
var a = 10;
do {
a += 1;
console.log(a);
} while (a < 5);
[A]11121314
[B]1112
[C]12345
[D]11
Show Answer
Correct Answer: 11
Notes:
Answer: d
Explanation: dowhile loop first executes the statements and after that checks for the condition. Therefore dowhile loop will be executed and after that the condition will become false and the loop will terminate.
76). What will be the output of the following JavaScript code?
var a= 0;
var b = 0;
while (a < 3)
{
a++;
b += a;
console.log(b);
}
[A]135
[B]123
[C]013
[D]01
Show Answer
Correct Answer: 135
Notes:
Answer: a
Explanation: A while loops checks for the condition first before executing the looping statements. A while loop increments the value at the end of the loop whereas for executes the statement at the starting of the loop.
77). What will be the output of the following JavaScript code?
int size=5;
int a=5;
int size=4;
for(int j=size;j>=0;j--)
{
console.log(a);
a=a-2;
}
[A]5555
[B]5321
[C]531-1
[D]531
Show Answer
Correct Answer: 531-1
Notes:
Answer: c
Explanation: The value of a will decrease by 2 at every iteration. The for loop will iterate four times till the value of j will decrease to 0.
78). What will be the output of the following JavaScript code?
int a=0;
for(a;a<5;a++);
console.log(a);
Show Answer
Correct Answer: 5
Notes:
Answer: d
Explanation: The value of a will increase until it will become equal to 5 after that the cursor will come out the loop. There are no statements for the for loop therefore only the value of a will increase. Hence the output will be five.