If you click on the Home > Insulation link right under your question, you can find a number of prior questions with responses regarding types of insulation and using sheet foam or foam-in-place insulation.
A lot of factors come into play inthe economics. Generally speaking, in "new" construction (including insulating walls/ceilings etc that are fully opened up due to remodel or upgrading an area), both rigid board and foam in place is more expensive than fiberglass batt or roll insulation, both total job cost and per insulating "R" unit.
However, there are places it is especially nice - in insulating walls without having to remove the drywall it is certainly cheaper because you only have a few small holes too patch in the drywall in each stud bay rather than mostly or entirely removing the drywall, in locations where it is very difficult to get into to put in batt insulation like very low headroom crawlspaces, in areas where total airflow sealing is needed but difficult like rimjoist areas and the like, and in thin locations where normal thickness fiberglass will not fit.
Foam in place- at least closed-cell - can also be more resistant to mildew in locations that might get damp (especially if a mildewcide is added to the mix, which is easy and cheap), and is especially nice for coating the underside of warm roofs like concrete or commercial- bottom-exposed steel raised seam roofing, though that situation is unusual in residential construction. And of course,with the correct protective paint, it is about the only feasible solution for the rare instance where exterior insulation is called for, though that is pretty rarely appropriate for residential uses.
Rigid closed-cell board insulation, and to a conditional extent foam-in-place, is also nice in areas with cold walls and possibility of condensation due to low airflow, like basements that are not fully air conditioned or have damp slab conditions so condensation on the foundation wall inside the architectural inner studwall is possible. In that environment, you have a sticky question to consider and there is no general "right" answer - fiberglass insulation allows the wall to "breathe" more but can also hold moisture on the fibers and mildew, board insulation without sealing the edges allows a certain amount of moisture through the wall to evaporate into the room especially if you build it as a "ventilated wall" with vertical airflow between the drywall (hopefully using water resistant "greenboard" in that instance) and the insulation. However, foam-in-place, especially if the studs are blocked out from the foundation wall 1/2" or so to allow the foam to make full contact with the foundation material behind the studs, can act as a moderate barrier to water vapor coming through the wall. Any insulating system can result moisture buildup and mold issues depending on the temperatures and humidities at the wall surface and in the room, and on the amount of water vapor coming through the foundation, so each case requires its own design.
One other consideration - if you have utility lines that might need work in the future (especially if older ones, not being replaced at this time) fiberglass is the easiest insulation to work around, board more difficult, and foam-in-place can be a real pain to make repairs in - both because it bonds to everything so has to be cut or scraped off the work area, and because it prevents you from pulling pipes or wires - either to gain a bit of slack or to install new ones, until you cut a channel through it. Ditto if you think you might ever tear this wall out in a future remodel - because foam-in-place makes an awful mess to clean off of foundation surfaces, though that issue can be reduced buy putting a barrier in first - vapor barrier if the wall design is being sealed at the foundation and making the interior surface permeable; or vapor-permeable roof or house wrap if the vapor barrier is going on the inside of the wall.
One thing about fiberglass in basement walls - I recommend never using kraft faced batts or rolls there - the paper mildews/molds too easy.