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/5Score 0

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

Questions in this quiz
  1. Why is a boolean "flag parameter" (e.g. `save(user, true)`) considered a code smell?
  2. 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?
  3. 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`?
  4. Treating error handling as a first-class concern rather than an afterthought means:
  5. 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?
  6. What is a "code smell" in clean-code terminology?
  7. 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?
  8. 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?
  9. A function has 7 parameters, several of them optional booleans controlling different behavior branches inside it. What does clean-code guidance suggest?
  10. What is a key risk of comments that clean-code guidance warns about?
  11. What is wrong with encoding a variable's type into its name, e.g. `usersArray` or `nameStr`?
  12. A teammate needs a comment to explain what a function named `chk(u, r)` does. What is the clean-code fix?
Gaps to close?
Read the curated Clean Code notes — core concepts, patterns, interview prep.
Clean Code notes

More quizzes

.NET.NET MAUIAbsintheAccessibilityActixActix Web