My Report

JavaScript Loops Test


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. 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);
}

2. What will be the step of the interpreter in a jump statement when an exception is thrown?

3. What will be the equivalent code of the following JavaScript code?

for(var p in o)
   console.log(o[p]);

4. What will be the output of the following JavaScript code?

let size = 5;
let a = 5;
for (let j = size; j >= 0; j=a) {
    document.write(a);
    a = a - 2;
}

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

6. What will be the output of the following JavaScript code?

var a = 10;
do {
  	a += 1;
  	console.log(a);
} while (a < 5);	

7. What could be the task of the statement debugger in the following JavaScript code?

function f(o) 
{
     if (o === undefined) debugger;
}

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

9. What will be the output of the following JavaScript code?

let a = 0;
for (a; a < 5; a++);
console.log(a);

10. What will be the role of the continue keyword in the following JavaScript code snippet?

while (a != 0)
{
   if (a == 1) 
       continue;
   else 
       a++;
}

11. One of the special features of an interpreter in reference with the for loop is that ___________

12. 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);
     }
}

13. What are the three important manipulations done in a for loop on a loop variable?

14. Among the keywords below, which one is not a statement?

15. What will be the output of the following JavaScript code?

function range(int length)
{
	var a=5;
	for(var i=0;i<length;i++)
	{
		console.log(a);
	} 
}
range(3);

 

Start practicing “1000 MCQs on JavaScript”, and once you are ready, you can take tests on all topics by attempting our “JavaScript Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.