Compound interest is indifferent to which direction it runs. On debt, the interest you don't pay gets added to the balance, and next month's interest is charged on the larger amount. At credit-card rates — often 20% or more annually — this compounds fast enough that minimum payments can keep you in debt for decades on a balance you could otherwise clear in a couple of years.
This produces a clean rule: paying off high-interest debt is a guaranteed, risk-free return equal to the interest rate. Clearing a 22% credit card is mathematically equivalent to earning a guaranteed 22% on an investment — better than any realistic market return, with zero risk. This is why the standard sequencing is: clear high-interest debt before investing anything beyond an employer match. The exception is low-rate debt (a cheap mortgage), where investing may reasonably win.