Spray foam and fiberglass batts are two common insulation choices with very different strengths. Batts are cheap and DIY-friendly; spray foam costs more but air-seals as it insulates.
Cost and installation
Fiberglass batts are inexpensive and easy to install yourself in open walls and attics. Spray foam costs several times more and is usually professionally installed, but it expands to fill gaps and seal air leaks in one step.
R-value and air sealing
Spray foam delivers higher R-value per inch and, crucially, air-seals — stopping the leaks that let heated air escape. Batts have good R-value but don't seal air, so they only perform well when air leaks are sealed separately. Closed-cell foam also resists moisture.
Which to choose
Use batts for open, easy-to-access cavities on a budget where you'll air-seal separately. Use spray foam for hard-to-seal areas, rim joists, irregular spaces, and where you want air sealing and insulation in one step — like an older, leaky home or a basement.