Refactoring technique: Replace conditional with descriptive variable
23 November 2023 (Updated 23 November 2023)
Before
if (product.price > 100 && product.isInStock() && customer.hasLoyaltyCard()) {
applySpecialDiscount()
}
After
const isEligbleForDiscount = product.price > 100 && product.isInStock() && customer.hasLoyaltyCard()
if (isEligibleForSpecialDiscount) {
applySpecialDiscount()
}
Tagged:
Refactoring
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment