Fix mixed string and number addition
Form values arrive as strings. Here the tax is numeric, but the final + can concatenate if price remains a string.
function totalWithTax(price, rate) {
return price + price * (rate / 100);
}
Convert the external value to a number before doing arithmetic.
What change makes totalWithTax("20", 10) return the number 22?
Why it matters: Explicitly converting external values prevents surprising implicit coercion.