There are pros and cons to each option.
Anchoring requires evaluation of the location in terms of the bottom type,
depth, protection from the
wind, protection from waves, positioning relative to other boats, as well as the
weather forecast. It also requires supervision. Leaving your
boat unattended at anchor is not something to be done casually, without a very high degree of confidence that it will be there when you get back. You also have to be highly mindful of others who have anchored around you, that they are positioned in a way that they are not a threat to your
boat and that they are secure. Advantages to
anchoring are it's free, you have privacy (much of the time), you have a breeze over the boat, a great view, can go swimming, etc.
A mooring is halfway between anchoring and taking a slip, in many respects. You don't always know the quality of the mooring fittings, so some caution is required. Sometimes it's free, most of the time it's not. You're close to shore and services, groceries, etc.
A slip is obviously the most expensive. Downsides are lack of privacy,
noise, potential for theft, and it can be hot and the boat not well ventilated. Upsides are convenience, not having to worry about the
security of the boat for the most part, and generally better protection from
weather.
In general I anchor where and when I can, and that's about 95% of how the boat spends it's nights. I'll pull into a marina after a long
passage, to do some
work on the boat or do a major resupply. There are also some places where the convenience of being at a
dock given what you want to do ashore is just worth it.
A lot of US towns have city docks that are cheaper than
commercial marinas, but with fewer amenities. I tend to pull into those when I can.
As Mike said there are varying regulations/laws/etc regarding
anchorages and moorings from municipality to municipality, country to country. It's all over the map in fact.
If you're curious about anchoring, mooring, and slips in your area, take a look at the "live map" at ActiveCaptain.com. You need to create an account but it's free. The map has icons for user submitted content on
anchorages, moorings and slips. A review of it will give you some sense of what available.