LearnFrenzy
Sign in Take a free test

Loops · Exercise 1 of 4

Loops JavaScript Loops MCQ

  • 15 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Fifteen multiple-choice questions on JavaScript loops: for, while and do…while, for…of vs for…in, iterables, break, continue and labels, forEach, sparse arrays and key order. Pick an option to check your answer instantly.

Question 11 Medium

What is special about let i in for (let i = 0; i < 3; i++)?

A i is shared by all iterations, like var
B Each iteration gets a new binding of i, so callbacks created in the loop keep their own value
C i becomes a global variable
D i is read-only inside the body
Question page & discussion
Question 12 Medium

What does return do inside a forEach callback?

A Ends only the current callback call; forEach moves on to the next element
B Stops the whole forEach
C Returns a value from the enclosing function
D Throws an error
Question page & discussion
Question 13 Hard

How many times does [1, , 3].forEach(fn) call fn?

A 3 – the hole is passed as undefined
B 2 – forEach skips the hole
C 1
D 0 – sparse arrays cannot be iterated
Question page & discussion
Question 14 Medium

You need to know whether any order is above ₹10,000 and want to stop checking as soon as one is found. Which method fits?

A orders.forEach((o) => o.total > 10000)
B orders.map((o) => o.total > 10000)
C orders.filter((o) => o.total > 10000).length
D orders.some((o) => o.total > 10000)
Question page & discussion
Question 15 Hard

"hi😀".length is 4. How many times does for (const ch of "hi😀") run?

A 4 – once per UTF-16 unit
B 2
C 3 – for…of iterates by code point, so the emoji is one character
D 5
Question page & discussion
Up next · Exercise 2Predict the Output20 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links