Heart attacks can be prevented by lifestyle changes such as eating a healthy diet, exercising regularly, and quitting smoking. Medications such as aspirin and statins can also help prevent heart attacks by reducing the risk of atherosclerosis and blood clots.