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

Why is a boolean "flag parameter" (e.g. `save(user, true)`) considered a code smell?

In this round
  1. Why is a boolean "flag parameter" (e.g. `save(user, true)`) considered a code smell?
  2. 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?
  3. A teammate needs a comment to explain what a function named `chk(u, r)` does. What is the clean-code fix?
  4. Which version of a magic-number check is the clean-code choice? A) `if (user.orders.length > 10) applyDiscount(0.2)` B) `const VIP_ORDER_THRESHOLD = 10 const VIP_DISCOUNT_RATE = 0.2 if (user.orders.length > VIP_ORDER_THRESHOLD) applyDiscount(VIP_DISCOUNT_RATE)`
  5. 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`
  6. 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?
  7. What is the best test for whether a function is doing "one thing," per clean-code guidance?
  8. What is the main problem with a variable named `data` holding a list of active user records?
  9. What is wrong with encoding a variable's type into its name, e.g. `usersArray` or `nameStr`?
  10. A block of code has a comment reading `// check if user can edit (admin or owner)` directly above a function named `chk(u, r)`. What is the clean-code critique?
  11. What is the risk of a function name like `processAndValidateAndSave(order)`?
  12. Compare two ways of writing input validation for `title` and `body` fields, duplicated identically inside both `createPost(data)` and `updatePost(data)`, versus extracting it into a shared `validatePost(data)` called by both. Which is the clean-code choice and why?
Gaps to close?
Read the curated Clean Code notes — core concepts, patterns, interview prep.
Clean Code notes

More quizzes

.NETAccessibilityAgile MethodologyAlertmanagerAlgorithmsAndroid