All quizzes
Free quiz · 28 questions in the bank

Clean Code quiz

Test your Clean Code knowledge with a free interactive quiz — 28 questions with answers and explanations. No signup needed to play.

Question 1/12Score 0

What is the main problem with a variable named `data` holding a list of active user records?

In this round
  1. What is the main problem with a variable named `data` holding a list of active user records?
  2. A catch block re-throws with `throw new Error('Failed to save user ' + user.id, { cause: err })`. What is the purpose of preserving `err` as `cause`?
  3. Two versions of an error handler: A) `try { db.users.save(user) } catch (e) { console.log('error') }` B) `try { return db.users.save(user) } catch (err) { throw new Error(`Failed to save user ${user.id}: ${err.message}`, { cause: err }) }` Which is the clean-code choice?
  4. A function `calculateTotal(cart)` is extracted out of a larger `checkout()` function so it can be unit tested independently. What is the primary clean-code benefit of this extraction?
  5. A teammate needs a comment to explain what a function named `chk(u, r)` does. What is the clean-code fix?
  6. Which function name is the clean-code choice for a function that returns milliseconds elapsed for a given number of days?
  7. Which comment adds real value under clean-code guidance? A) `// increment i by 1` above `i++` B) `// Stripe webhooks can arrive out of order during retries, so we ignore events older than the one we already processed` above an `if (event.createdAt < lastProcessedEvent.createdAt) return`
  8. Compare these two versions of a discount check: A) `if (user) { if (user.isActive) { if (user.orders.length > 10) { return 0.2 } else { return 0.1 } } else { return 0 } } else { return 0 }` B) `if (!user || !user.isActive) return 0 if (user.orders.length > 10) return 0.2 return 0.1` Which is cleaner, and why?
  9. What does the "Boy Scout Rule" mean in the context of clean code?
  10. What is the best test for whether a function is doing "one thing," per clean-code guidance?
  11. A `checkout(cart, user)` function validates the cart, computes tax, saves the order, and sends a confirmation email -- all in one function body. What clean-code principle does this violate?
  12. What is a "code smell" in clean-code terminology?
Gaps to close?
Read the curated Clean Code notes — core concepts, patterns, interview prep.
Clean Code notes

More quizzes

.NET.NET MAUIAbsintheAccessibilityActixActix Web