Why do cacti have thorns?

Cacti plants are mainly found in North and Central America, although they can grow anywhere.

They do not have leaves to store water, it is stored in the spines.  The spines also work as a protector for the plant against desert or other animals from eating them to quench their thirst.

This will then ensures the survival of the plant long enough to reproduce and carry on the survival of its species.