GkSeries.com

JavaScript Questions & Answers – Statements | JavaScript MCQs

(1) JavaScript is a _______________ language.
[A] Object-Oriented
[B] High-level
[C] Assembly-language
[D] Object-Based
Answer: Object-Based
(2) What will be the output of the following JavaScript code?
var a=5 , b=1
var obj = { a : 10 }
with(obj) 
{
      alert(b)
}
[A] 10
[B] Error
[C] 1
[D] 5
Answer: 1

DOWNLOAD CURRENT AFFAIRS PDF FROM APP

(3) A conditional expression is also called a _______________
[A] Alternative to if-else
[B] Immediate if
[C] If-then-else statement
[D] Switch statement
Answer: Immediate if
(4) 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++; }
[A] Code 1
[B] Code 2
[C] Both Code 1 and Code 2
[D] Cannot Compare
Answer: Code 1
(5) What is a block statement in JavaScript?
[A] conditional block
[B] block that contains a single statement
[C] both conditional block and a single statement
[D] block that combines multiple statements into a single compound statement
Answer: block that combines multiple statements into a single compound statement
(6) When an empty statement is encountered, a JavaScript interpreter __________
[A] Ignores the statement
[B] Prompts to complete the statement
[C] Throws an error
[D] Shows a warning
Answer: Ignores the statement
(7) The “var” and “function” are __________
[A] Keywords
[B] Declaration statements
[C] Data types
[D] Prototypes
Answer: Declaration statements
(8)

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

switch(expression)
{
    statements
}
[A] ==
[B] equals
[C] equal
[D] ===
Answer: ===
(9) What happens in the following javaScript code snippet?
var count = 0;
while (count < 10) 
{
    console.log(count);
    count++;
}
[A] The values of count are logged or stored in a particular location or storage
[B] The value of count from 0 to 9 is displayed in the console
[C] An error is displayed
[D] An exception is thrown
Answer: The value of count from 0 to 9 is displayed in the console
(10) The enumeration order becomes implementation dependent and non-interoperable if ___________
[A] If the object inherits enumerable properties
[B] The object does not have the properties present in the integer array indices
[C] The delete keyword is never used
[D] Object.defineProperty() is not used
Answer: If the object inherits enumerable properties
(11) What will be the output of the following JavaScript code?
Int a=1;
if(a>10)
{  
    document.write(10); 
}
else
{
    document.write(a);
}
[A] 10
[B] 0
[C] 1
[D] Undefined
Answer: 1
(12) What will be the output of the following JavaScript code?
var grade='B'; 
var result; 
switch(grade)
{ 
   case 'A':
    {  
        result+="10";
        break;
    } 
   case 'B':>
    {  
        result+=" 9";
        break;
   }  
    case 'C':
   { 
        result+=" 8";
        break;
        }  
    default:  
    result+=" 0";  
}  
document.write(result);
[A] 10
[B] 9
[C] 8
[D] 0
Answer: 9
(13) What will be the output of the following JavaScript code?
var grade='A'; 
var result;
switch(grade)
	{  
   case 'A': 
        result+="10";  
    	case 'B': 
        result+=" 9"; 
   	case 'C': 
       	result+=" 8"; 
    	default:
        result+=" 0"; 
}  
document.write(result);
[A] 10
[B] 27
[C] 8
[D] 0
Answer: 27
(14) What will be the output of the following JavaScript code?
int a=4;
int b=1;
int c=0;
If(a==b)
    	document.write(a);
	else if(a==c)
    	document.write(a);
else
    	document.write(c);
[A] 4
[B] 1
[C] Error
[D] 0
Answer: 0
(15) What will be the output of the following JavaScript code?
var grade='E';
var result;  
switch(grade)
{  
    case 'A':  
       result+="10";
    	case 'B':  
        result+=" 9";  
    case 'C':  
        result+=" 8";
    default: 
        result+=" 0";
} 
document.write(result);
[A] 10
[B] 0
[C] 18
[D] 17
Answer: 0

Please share this page

Click Here to Read more questions

Teacher Eligibility Test