18

Split Variable


Goal

Each variable has one role; reassignment patterns reflect distinct purposes rather than reused storage.

Before the refactoring
let temp = 2 * (height + width);
console.log(temp);
temp = height * width;
console.log(temp);
After the refactoring
const perimeter = 2 * (height + width);
console.log(perimeter);
const area = height * width;
console.log(area);
Savings

Names match purpose; the type system can narrow each role; refactoring each use becomes local.

Note

Two distinct uses of one variable share a single update pattern that may have hidden coupling — verify each use is genuinely independent.