Three materials, three jobs they are actually good at.
The honest comparison is not which material is best. It is which material belongs on the surface you are insulating. Fiberglass batts are cheap and work on a clean, sealed, dry cavity. Cellulose is inexpensive per R-value and settles into irregular spaces. Foam air-seals as well as insulates, and costs more for it.
Closed cell is the densest at roughly 6.5 to 7 per inch, open cell sits around 3.5 to 3.8, and fiberglass and cellulose are both lower per inch than closed cell. In a shallow cavity - a rim joist, a 2x4 wall, a furred masonry wall - the per-inch number decides what you can physically fit, so it matters more than the per-dollar number.
Fiberglass and cellulose are air-permeable. They insulate; they do not stop air. Every assembly insulated with them still needs a separate air-sealing step, and in old houses that step is where most of the savings live. Foam does both jobs in one pass, which is the real reason it costs more and also the reason a rim joist with foam is a different job from a rim joist with a batt.
In a cold climate, a vapor-permeable material on the cold side of a wet assembly is how mold starts. Closed cell is the safest choice against a cold surface; open cell needs a vapor strategy; fiberglass against masonry is the classic failure, which is why so many Boston rim joists have a rotted sill behind a dry-looking batt.
Foam wins on rim joists, crawlspace walls, furred masonry, shallow cavities and anything that has to air-seal. Cellulose wins on a large flat attic you can blow into. Fiberglass wins on a clean, sealed, dry cavity with depth to spare, where the budget is the constraint.
No. On a large flat ceiling with a clean cavity, fiberglass or cellulose plus proper air-sealing reaches a similar result for less money. Foam is better where space is thin or air-sealing is the main goal.
Cellulose is the value choice for a deep, open attic ceiling. It settles and fills irregularities well, and it still needs the air-sealing done first.