Question 10
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const stock = new Map([["pen", 10], ["ink", 0], ["pad", 3]]);
for (const [item, qty] of stock) {
if (!qty) console.log(`${item} out of stock`);
}
- A pen out of stock
- B ink out of stock Correct
- C ink out of stock pad out of stock
- D Nothing is printed
Correct Answer: Option B
Iterating a Map yields [key, value] pairs, which the loop head unpacks; only ink has a falsy quantity.
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!