Iteration structures in JavaScript allow developers to execute code blocks repeatedly based on dynamic boolean conditions. Standard loops such as for, while, and do...while handle basic numerical iteration and pre/post-condition checks. ECMAScript 2015 (ES6) introduced specialized iteration mechanisms: for...in for enumerating non-Symbol object property keys, and for...of for traversing iterable collections like Arrays, Strings, Sets, and Maps. Mastering loop control statements (break, continue, and labeled statements), along with understanding closure scoping behaviors when using let versus var in iteration headers, is essential for writing efficient runtime code and excelling in technical interviews.
JavaScript Loops MCQs
1 min read
Correct Answer: b) 02
Explanation:
The variable i starts at 0 and increments by 2 on each iteration (i = 0, i = 2). When i becomes 4, the condition i < 4 evaluates to false, leaving str as '02'.
Correct Answer: c) No output
Explanation:
The initial condition x > 5 is false because 5 > 5 is false. The body of the while loop never executes.
Correct Answer: a) 5
Explanation:
A do...while loop runs the loop body once before evaluating the condition. 5 is printed, x becomes 4, and then 4 > 5 evaluates to false, terminating the loop.
Correct Answer: b) abc
Explanation:
The for...in loop iterates over the enumerable property names (keys) of an object. Concatenating them results in 'abc'.
Correct Answer: b) 6
Explanation:
Sets only store unique values, so the Set contains [1, 2, 3]. Iterating over these values with for...of gives 1 + 2 + 3 = 6.
Correct Answer: b) 2
Explanation:
When i = 0, count becomes 0. When i = 1, continue skips the addition. When i = 2, count becomes 0 + 2 = 2.
Correct Answer: a) 00
Explanation:
When i = 0, j = 0 logs '00'. Next, for j = 1, the condition (i === 0 && j === 1) is true, executing 'break outer', which immediately terminates the outer loop.
Correct Answer: c) The condition defaults to true, resulting in an infinite loop unless broken internally
Explanation:
In JavaScript for loops, an omitted condition section defaults to evaluating as true, creating an infinite loop.
Correct Answer: b) string string string
Explanation:
The for...in loop yields key names as strings, even when iterating over array index positions.
Correct Answer: a) number number number
Explanation:
The for...of loop yields array values directly, which are primitive numbers in this array.
Correct Answer: b) 3
Explanation:
Variables declared with 'var' are function-scoped or globally scoped, so 'i' remains accessible after the loop ends with the value 3.
Correct Answer: c) ReferenceError
Explanation:
Variables declared with 'let' inside a for loop statement are block-scoped to the loop, causing a ReferenceError if accessed outside.
Correct Answer: b) for await...of
Explanation:
The 'for await...of' statement allows creating a loop iterating over asynchronous iterable objects sequentially.
Correct Answer: b) 1
Explanation:
The do...while loop body runs once unconditionally before checking (1 < 0), which is false, terminating the loop with count = 1.
Correct Answer: a) a:1 b:2
Explanation:
Iterating over a Map using for...of yields key-value pair arrays, which are destructured into `key` and `val`.
Correct Answer: b) Plain objects throw a TypeError if used directly with for...of because they lack an @@iterator method.
Explanation:
Plain objects are not built-in iterables. Using `for (const x of {})` throws a `TypeError: {} is not iterable`.
Correct Answer: a) Object.entries(obj)
Explanation:
Object.entries(obj) returns an array of [key, value] pairs, which is an iterable structure compatible with for...of.
Correct Answer: a) 2
Explanation:
For each of the 2 outer iterations, the inner loop runs j=1 (adds 1 to result) and then j=2 hits 'break', exiting the inner loop. Total = 1 + 1 = 2.
Correct Answer: a) 3
Explanation:
When i reaches 3, the condition (i === 3) evaluates to true and executes 'break', terminating the loop while i is equal to 3.
Correct Answer: a) 1 3
Explanation:
i increments to 1 (logged). Then i increments to 2; (i === 2) is true, so continue skips logging. Then i increments to 3 (logged). Loop terminates.
Correct Answer: b) 2
Explanation:
Strings are iterable objects. The for...of loop inspects each character in "hello" and increments count for the two 'l' characters.
Correct Answer: a) It throws a TypeError during that iteration.
Explanation:
Declaring `for (const key in obj)` creates a new `const` binding for each iteration. Reassigning `key` inside the loop body throws a TypeError.
Correct Answer: b) It iterates over own and inherited enumerable string properties.
Explanation:
The for...in loop traverses all enumerable string properties of an object, including those inherited along its prototype chain.
Correct Answer: a) By using Object.hasOwn(obj, prop) or obj.hasOwnProperty(prop)
Explanation:
Filtering with `Object.hasOwn(obj, prop)` inside the loop body screens out inherited properties from prototype chains.
Correct Answer: b) 2 1 0
Explanation:
Condition check returns 3 (truthy), then i becomes 2 (logged). Check returns 2, i becomes 1 (logged). Check returns 1, i becomes 0 (logged). Check returns 0 (falsy), loop ends.
Correct Answer: c) 2 1
Explanation:
--i decrements i to 2 first (truthy, logged). Then decrements to 1 (truthy, logged). Next decrements to 0 (falsy, loop ends). Output: '2 1'.
Correct Answer: a) 6
Explanation:
The loop skips odd numbers and sums even numbers: i = 0, 2, 4. Total = 0 + 2 + 4 = 6.
Correct Answer: b) It throws a SyntaxError.
Explanation:
Unlike 'break', which can target any labeled block, a labeled 'continue' statement can ONLY target a labeled loop statement.
Correct Answer: b) A
Explanation:
A labeled 'break' statement can be used with arbitrary block statements to exit the block early.
Correct Answer: b) 6
Explanation:
The total combinations of (i, j) for 3x3 is 9. The condition (i === j) matches 3 times (0,0; 1,1; 2,2) and skips them, leaving 9 - 3 = 6.
Correct Answer: a) Symbol.iterator
Explanation:
An object becomes iterable for 'for...of' when it implements a method whose key is Symbol.iterator.
Correct Answer: a) a
Explanation:
At i = 0, str becomes 'a'. At i = 1, break executes immediately before appending 'b', terminating the loop.
Correct Answer: c) No output
Explanation:
Condition (10 < 10) is false initially, so the while loop body is skipped completely.
Correct Answer: b) 4
Explanation:
The outer for loop runs 2 times. For each outer pass, the inner while loop runs 2 times, yielding 2 * 2 = 4 counts.
Correct Answer: a) for await...of
Explanation:
The 'for await...of' statement awaits promises yielded by an asynchronous iterable or generator during iteration.
Correct Answer: b) 12
Explanation:
The loop retrieves property keys ('x', 'y') and accesses object property values via `obj[key]`, concatenating '1' and '2' to get '12'.
Correct Answer: b) 3
Explanation:
Omitting initialization and step expressions in a for loop header is valid syntax. i increments from 0 to 3, ending the loop.
Correct Answer: b) undefined
Explanation:
Wait, 'i' is block-scoped to the loop. Accessing 'i' outside throws a ReferenceError, but `typeof i` safely evaluates to "undefined" for undeclared block variables.
Correct Answer: a) 3
Explanation:
i = 1 adds 1. i = 2 adds 2 (total = 3). i = 3 hits 'break' and exits immediately. Final total = 3.
Correct Answer: b) It terminates both the loop and the entire function execution, returning the specified value.
Explanation:
A 'return' statement inside a loop ends function execution immediately, returning control to the caller.
Correct Answer: a) 2
Explanation:
When i reaches 2, the function immediately returns 2, ending both loop and function execution.
Correct Answer: a) 012
Explanation:
Iterations append i: 0 (i becomes 1), 1 (i becomes 2), 2 (i becomes 3). Condition (3 < 3) is false. Result is '012'.
Correct Answer: b) Throws TypeError
Explanation:
Attempting to reassign the loop variable 'val' declared with 'const' inside the loop body throws a TypeError.
Correct Answer: b) ['a', 'b']
Explanation:
Reassigning the local loop variable 'val' only alters the primitive binding inside the iteration scope, not the original array elements.
Correct Answer: a) 00 01 10 11
Explanation:
Outer loop i=0 runs inner loop j=0,1 ('00', '01'). Outer loop i=1 runs inner loop j=0,1 ('10', '11').
Correct Answer: c) Plain Object ({})
Explanation:
Standard plain JavaScript objects `{}` do not implement the iterator protocol and cannot be looped over using `for...of` directly.
Correct Answer: a) 5
Explanation:
count increments for i = 0, 1, 2, 3, 4 (count becomes 5). When i = 5, break executes before incrementing count.
Correct Answer: a) 7
Explanation:
i = 0, 1, 2 are skipped by continue. For i = 3 and 4, val += i computes 3 + 4 = 7.
Correct Answer: b) It exits the loop containing the try-catch block.
Explanation:
A break statement inside a catch block breaks out of the enclosing loop containing the try-catch structure.
Correct Answer: a) 02
Explanation:
When i = 0, res becomes '0'. When i = 1, i increments to 2 and continue skips appending. When i = 2, res becomes '02'. Loop ends.
Correct Answer: a) 3
Explanation:
Wait, let's trace: i=0 (add 0), i=1 (add 1), i=2 (add 2). Total x = 0 + 1 + 2 = 3.
Correct Answer: b) 9
Explanation:
Since 'var' creates a single shared variable 'i' that equals 3 after loop completion, all 3 timeout callbacks add 3 to x, yielding 3 + 3 + 3 = 9.
Correct Answer: b) It is valid JavaScript syntax creating a loop that runs indefinitely until broken.
Explanation:
All three expressions in a standard for loop are optional. `for (;;)` is valid syntax creating an infinite loop.
Correct Answer: b) 321
Explanation:
Prepending each character (`out = char + out`) reverses the order of elements from "123" to "321".
Correct Answer: a) 3
Explanation:
Modifying the array length during iteration would normally extend the loop, but the explicit `count === 3` condition breaks the loop at 3 iterations.
Correct Answer: a) 12
Explanation:
When i = 0: default runs (a = 1). When i = 1: case 1 runs (a = 1 + 10 = 11). When i = 2: default runs (a = 11 + 1 = 12).
Correct Answer: b) No, it exits only the switch block, allowing the loop to continue.
Explanation:
An unlabelled 'break' inside a switch block terminates only the switch statement, not the surrounding loop.
Correct Answer: a) Using a labeled break statement targeting the outer loop label
Explanation:
Prefixing the outer loop with a label (e.g., `outerLoop: for(...)`) allows `break outerLoop;` from within an inner switch block.
Correct Answer: a) 3
Explanation:
When i = 0, inner loop runs 3 times (res = 3). When i = 1, `break loop1` executes immediately, terminating the outer loop.
Correct Answer: a) 3
Explanation:
For each outer iteration (i = 0, 1, 2), j = 0 increments res (1 per outer pass), then j = 1 hits `continue loop1`, skipping j = 2 and starting the next outer iteration. Total res = 3.
Correct Answer: b) The numeric index positions as strings ("0", "1", ...)
Explanation:
for...in iterates over property keys of an object. For strings, key names are index character strings ("0", "1", etc.).
Correct Answer: a) The string characters
Explanation:
for...of iterates over values of iterable objects. For strings, it yields individual string characters.
Correct Answer: a) 3
Explanation:
x accumulates 0 + 1 + 2 = 3.
Correct Answer: c) 0 1 customProp
Explanation:
for...in iterates over ALL enumerable string properties of an object, including custom added properties on array instances.
Correct Answer: b) 10 20
Explanation:
for...of uses the array's built-in iterator, which iterates strictly over indexed array elements [10, 20], ignoring non-indexed properties.
Correct Answer: a) 3
Explanation:
Loose equality (i == "3") performs type coercion. When i = 3, 3 == "3" is true, triggering break and leaving count = 3.
Correct Answer: b) 5
Explanation:
Strict equality (i === "3") checks types without coercion. Number i never strictly equals string "3", so break never triggers and count becomes 5.
Correct Answer: b) The loop body executes exactly once.
Explanation:
The condition check occurs at the end of the block in a do...while loop, guaranteeing one execution pass regardless of condition state.
Correct Answer: b) 321
Explanation:
i starts at 3 and decrements through 3, 2, 1. When i reaches 0, condition i > 0 fails. Output is '321'.
Correct Answer: a) 3
Explanation:
i = 0 is skipped by continue. i = 1 adds 1. i = 2 adds 2. Total a = 1 + 2 = 3.
Correct Answer: c) Both forms produce identical loop behavior and iteration count.
Explanation:
The step expression in a for loop runs at the end of each iteration. Whether prefix (++i) or postfix (i++) is used, the increment value is discarded and produces identical loop outcomes.
Correct Answer: a) 3
Explanation:
The object has 3 enumerable properties ('a', 'b', 'c'). The for...in loop runs 3 times.
Correct Answer: a) 1
Explanation:
Object.create(null) creates an object with no prototype. Adding property 'a' gives 1 enumerable key, so for...in runs 1 time.
Correct Answer: a) ***
Explanation:
The condition i === j matches 3 times across the nested grid (0,0; 1,1; 2,2), appending 3 asterisks.
Correct Answer: a) SyntaxError: Undefined label 'missingLabel'
Explanation:
Referencing an undefined label in a break or continue statement raises a parse-time SyntaxError.
Correct Answer: a) -2
Explanation:
Values of val: 10 -> 7 -> 4 -> 1 -> -2. At -2, condition (-2 > 0) evaluates to false, leaving val as -2.
Correct Answer: a) 14
Explanation:
Calculates sum of squares: 1^2 + 2^2 + 3^2 = 1 + 4 + 9 = 14.
Correct Answer: a) yield
Explanation:
The 'yield' keyword pauses generator function execution and returns a value to the caller.
Correct Answer: a) The loop body never executes.
Explanation:
Iterating over an empty iterable produces 0 iterations, skipping the loop body completely.
Correct Answer: a) The loop body never executes.
Explanation:
An empty array has no enumerable property keys, so for...in skips the loop body.
Correct Answer: a) 2
Explanation:
Iteration 1: i=0, a += 0 (a=0), i++ makes i=1. Loop step i++ makes i=2. Iteration 2: i=2, a += 2 (a=2), i++ makes i=3. Loop step i++ makes i=4. Loop ends. a = 2.
Correct Answer: a) ABAB
Explanation:
Outer loop i=0: appends 'A'. Inner loop j=0: appends 'B' and breaks inner loop. Outer loop i=1: appends 'A'. Inner loop j=0: appends 'B' and breaks. Result: 'ABAB'.
Correct Answer: a) 4
Explanation:
Outer loop runs for i=0 (inner runs 2 times, res=2), i=1 (skipped via continue), i=2 (inner runs 2 times, res=4).
Correct Answer: a) 3
Explanation:
x increments through 1, 2, 3. When x reaches 3, condition (x === 3) triggers break, exiting with x = 3.
Correct Answer: a) for...of sequentially awaits promises in body, while forEach runs callbacks concurrently without awaiting.
Explanation:
A for...of loop inside an async function properly pauses execution on `await`. Array.prototype.forEach invokes callback functions synchronously without awaiting promises.
Correct Answer: a) 60
Explanation:
Array.prototype.forEach executes the callback for each element in the array, accumulating 10 + 20 + 30 = 60.
Correct Answer: a) 0E2
Explanation:
i=0 logs '0'. i=1 throws error, catch block appends 'E'. i=2 logs '2'. Final output: '0E2'.
Correct Answer: c) 0FEF2F
Explanation:
i=0: appends '0' then 'F'. i=1: throws, catch appends 'E', finally appends 'F'. i=2: appends '2' then 'F'. Result: '0FEF2F'.
Correct Answer: b) A new scope created for each iteration step.
Explanation:
JavaScript creates a new per-iteration environment record for `let` declarations in for loop headers, enabling closures inside loops to capture correct values.
Correct Answer: a) 0 1 2
Explanation:
Because `let` creates a distinct variable binding per iteration, each closure captures its own iteration's value of `i`.
Correct Answer: b) 3 3 3
Explanation:
Because `var` is function-scoped, all closures bind to the same single variable `i`, which equals 3 after loop completion.
Correct Answer: a) ab
Explanation:
Iterating over string "a\nb" yields 'a', '\n', and 'b'. The condition skips the newline character, concatenating to 'ab'.
Correct Answer: a) 6
Explanation:
Total grid points = 9. The condition i + j === 2 matches for (0,2), (1,1), and (2,0), skipping 3 times. Remaining count = 9 - 3 = 6.
Correct Answer: a) 16
Explanation:
val sequence: 1 -> 2 -> 4 -> 8 -> 16. At 16, condition (16 < 10) is false, terminating loop with val = 16.
Correct Answer: a) 2
Explanation:
The do...while loop body runs once, setting val to 2. Condition (2 < 0) is false, terminating loop.
Correct Answer: a) break can be used in loops and switch statements; continue can only be used in loops.
Explanation:
The break statement applies to loops, switch statements, and labeled blocks. The continue statement applies exclusively to loops.
Correct Answer: a) 01
Explanation:
i=0 appends '0'. i=1 appends '1' and reassigns i to 5. The loop step i++ increments i to 6. Condition (6 < 3) is false, ending loop. Result: '01'.
Correct Answer: a) 0
Explanation:
Iteration 1: i=0, sum becomes 0, i reassigned to 2. Loop step i++ makes i=3. Condition (3 < 3) is false, ending loop. Final sum = 0.
Correct Answer: a) 3
Explanation:
text.length is 3. The loop runs for i = 0, 1, 2, incrementing count 3 times.
Correct Answer: a) 13
Explanation:
When val === 2, continue skips appending '2'. Output is '13'.
Correct Answer: a) expr1 runs once before loop; expr2 evaluated before each iteration; expr3 evaluated after each iteration body.
Explanation:
Initialization (expr1) executes once. Condition (expr2) is tested before each pass. Increment/step (expr3) evaluates after each pass.
Correct Answer: a) 9
Explanation:
i sequence: 5, 3, 1. (Next step is -1, which fails condition > 0). Sum = 5 + 3 + 1 = 9.
Correct Answer: a) olleh
Explanation:
The loop iterates backward through the string characters from last index to first index, reversing 'hello' to 'olleh'.
Related Posts

Java Functions MCQs
In Java, functions are formally known as methods and serve as modular blocks of reusable code encapsulated within classes. A…
October 19, 2026By MCQs Generator

JavaScript Control Flow MCQs
Control flow defines the order in which statements and expressions execute within a JavaScript program. At the heart of decision-making…
October 19, 2026By MCQs Generator

JavaScript Error Handling MCQs for Developer Interviews & Certification
Exception and error handling in JavaScript is essential for preventing runtime crashes and maintaining application stability across complex web environments.…
August 29, 2026By MCQs Generator
Related Categories

AI & Data Science MCQ
5 topics
By MCQs Generator

Arts & Humanities MCQ
4 topics
By MCQs Generator

Civil Engineering MCQ
4 topics
By MCQs Generator

Commerce & Business MCQ
4 topics
By MCQs Generator

Competitive Exams MCQ
5 topics
By MCQs Generator

Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator

General Knowledge MCQ
2 topics
By MCQs Generator

General Science MCQ
4 topics
By MCQs Generator

Law & Judiciary MCQ
3 topics
By MCQs Generator

Mechanical Engineering MCQ
4 topics
By MCQs Generator

Medical & Health Sciences MCQ
4 topics
By MCQs Generator

Modern Tech Fields MCQ
3 topics
By MCQs Generator