Start with the age
Most tank water heaters last around 8 to 12 years. A repair on a young unit is usually worth it; on an old one, the next fault is often close behind.
Look at the fault
Thermostats, elements and valves are routine repairs. A leaking tank is not repairable and means replacement.
Ask for both prices
A good contractor will give you the repair and replacement price side by side. This is general information for a sample site, not professional advice.