Question 3
Back to Exercise
JavaScript refuses to run the code below. Which statement correctly describes the problem?
const words = ["", "js", "", "css"];
const lengths = words.map((w) => {
if (w === "") continue;
return w.length;
});
console.log(lengths);
- A It prints [ 2, 3 ]
- B SyntaxError: continue is only allowed in loops, and the callback is a function – filter first, then map Correct
- C It prints [ undefined, 2, undefined, 3 ]
- D It prints [ 0, 2, 0, 3 ]
Correct Answer: Option B
"Illegal continue statement". To skip items, use words.filter(Boolean).map((w) => w.length), or flatMap returning [] for empty words.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!