There are two (2) types of spray foam:
1) Open cell low density spray foam
2) Closed cell high density spray foam
Open cell foam is recommended for use mainly in commercial applications. The material is less expensive but requires more depth to achieve vapor barrier. Due to the porous, spongy nature of the product, rodents can easily pull this material apart to gain entry to your building and to build nests. There can be issues with this type of foam curing properly as well as lengthy periods of "off-gassing" which can impact people and pets.
Closed cell foam has the highest R-value available in insulation materials. Spray foam is not the only or necessarily the best insulation material for all types of projects. There are a number of different options that are less costly than foam and are also quite effective in achieving the comfort you desire.