My Report

JavaScript Basic Online Test – 4


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 is a block statement in JavaScript?

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

var B = 65; // ASCII value of A
var grade = B;
var result = 0; // Initialize result here
switch(grade) {
    case 'A': {
        result += 10; 
        break;
    } 
    case 'B': {
        result += 9;
        break;
    }  
    case 'C': {
        result += 8;
        break;
    }  
    default:  
        result += 0;  
}  
document.write(result);

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

var a = 4;
var b = 1;
var c = 0;
if (a === b)
    document.write(a);
else if (a === c)
    document.write(a);
else
    document.write(c);

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

let a = 1;
if (a > 10) {  
    document.write(10);  
} else {
    document.write(a > 10);  
}

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

var a=5 , b=1
var obj = { a : 10 }
with(obj) 
{
      alert(b)
}

6. When an empty statement is encountered, a JavaScript interpreter __________

7. The enumeration order becomes implementation dependent and non-interoperable if ___________

8. What happens in the following javaScript code snippet?

var count = 0;
while (count < 10) 
{
     console.log(count);
     count++;
}

9. JavaScript is a _______________ language.

10. A conditional expression is also called a _______________

11. The “var” and “function” are __________

12. In the following switch syntax, the expression is compared with the case labels using which of the following operator(s)?

	
switch(expression)
{
    statements
}

13. Which is a more efficient JavaScript 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++;
}

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

var grade='C';  
var result = '';  
switch(grade)
{  
    case 'A':  
        result+=" 10";  
    case 'B':  
        result+=" 9";  
    case 'C':  
        result+=" 8";  
    default:  
        result+=" 0";  
}  
document.write(result);

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

var grade='A';  
var result=0;  
switch(grade)
{  
    case 'A':  
        result+=10;  
    case 'B':  
        result+=9;  
    case 'C':  
        result+=8;  
    default:  
        result+=0;  
}  
document.write(result);

 

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.