Core Concepts

refactor

/ ree-FAK-tor /

To refactor is to improve the structure of code — make it clearer, simpler, easier to change — without changing what it actually does. Same inputs, same outputs; only the insides get tidier.

It's cleaning the kitchen, not changing the recipe. The dish that comes out tastes exactly the same, but now the knives are where you expect them, the counter is wiped, and the next person can cook without hunting for everything.

Good refactoring is small and continuous: rename a confusing variable, split one giant function into a few clear ones, delete code nobody uses. Because behavior shouldn't change, a solid set of tests is your safety net — if they still pass afterward, you know you didn't quietly break anything.

// before: what does `d` even mean?
function f(d){return d*86400000}
// after: same result, now readable
function daysToMs(days){return days * 24 * 60 * 60 * 1000}

Same math, clearer intent — that's a refactor.

Resist mixing in new features mid-refactor — change structure or change behavior, but not both in one breath.

Also called
refactoringclean up coderestructure