JavaScript Questions & Answers – Statements | JavaScript MCQs
Questions
2
What will be the output of the following JavaScript code?
var a=5 , b=1
var obj = { a : 10 }
with(obj)
{
alert(b)
}
Answer: 1
⭐ Make GKSeries Your Preferred Source on Google
Add GKSeries as Preferred Source
3
A conditional expression is also called a _______________
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++;
}
Answer: Code 1
5
What is a block statement in JavaScript?
Answer: block that combines multiple statements into a single compound statement
6
When an empty statement is encountered, a JavaScript interpreter __________
Answer: Ignores the statement
8
In the following switch syntax, the expression is compared with the case labels using which of the following operator(s)?
switch(expression)
{
statements
}
Answer: ===
9
What happens in the following javaScript code snippet?
var count = 0;
while (count < 10)
{
console.log(count);
count++;
}
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 ___________
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);
}
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);
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);
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);
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);
Answer: 0