PRACTICE • LEARN • GROW
Module 2 Final Quiz: Control Flow MCQs
Solve topic-wise placement questions and improve your skills.
Module 2 Final Quiz: Control Flow Progress
0 of 12 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
Which of the following values is TRUTHY in JavaScript?
A.
0
B.
'' (empty string)
C.
[] (empty array)
D.
NaN
Explanation & Key
Correct Answer:
2
What will be printed by this switch statement?
const val = '1';
switch(val) {
case 1:
console.log('One');
break;
case '1':
console.log('String One');
default:
console.log('Done');
}
A.
String One
B.
One\nString One
C.
String One\nDone
D.
Done
Explanation & Key
Correct Answer:
3
What is the output of the following loop?
const arr = ['a', 'b'];
for (const x in arr) {
console.log(typeof x);
}
A.
'number' 'number'
B.
'string' 'string'
C.
'object' 'object'
D.
'undefined' 'undefined'
Explanation & Key
Correct Answer:
4
What is the output of the following hoisting snippet?
console.log(num);
var num = 10;
A.
10
B.
undefined
C.
ReferenceError
D.
null
Explanation & Key
Correct Answer:
5
What happens when executing this code?
console.log(val);
let val = 20;
A.
Prints undefined
B.
Prints 20
C.
Throws ReferenceError: Cannot access 'val' before initialization
D.
Throws TypeError
Explanation & Key
Correct Answer:
6
What is the output of this loop with asynchronous timeout?
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 0);
}
A.
0 1 2
B.
3 3 3
C.
undefined undefined undefined
D.
2 2 2
Explanation & Key
Correct Answer:
7
What is the output if 'let' is used instead in the loop?
for (let i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 0);
}
A.
0 1 2
B.
3 3 3
C.
1 2 3
D.
undefined undefined undefined
Explanation & Key
Correct Answer:
8
What is the output of calling a function before its declaration?
greet();
function greet() {
console.log('Hello');
}
A.
Hello
B.
TypeError: greet is not a function
C.
ReferenceError
D.
undefined
Explanation & Key
Correct Answer:
9
What is the output of calling a function expression before its definition?
sayHello();
var sayHello = function() {
console.log('Hi');
};
A.
Hi
B.
TypeError: sayHello is not a function
C.
ReferenceError
D.
undefined
Explanation & Key
Correct Answer:
10
What does a 'do...while' loop guarantee compared to a standard 'while' loop?
A.
It always runs asynchronously
B.
The loop body is guaranteed to execute at least once before the condition is checked
C.
It avoids stack overflow
D.
It only works with iterables
Explanation & Key
Correct Answer:
11
What is the output of the following equality?
console.log([] == false);
A.
true
B.
false
C.
TypeError
D.
NaN
Explanation & Key
Correct Answer:
12
What is the output of the following code snippet?
let x = 1;
{
console.log(typeof x);
let x = 2;
}
A.
'number'
B.
'undefined'
C.
ReferenceError
D.
'object'
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong