The function of a starfish's spines is to provide protection from sea otters, fish and birds that hunt starfish for prey. The spines are made of calcium carbonate, which forms a series of plates on the top of the starfish. Each plate features a set of small spines.
Turning over a starfish (or sea star) reveals an underside of spiny skin as well as a number of cylinders, which are the starfish's "feet." By moving these tubes, the starfish crawls around the beach; if high tide leaves a live starfish behind, it heads down the shore to get back into the water. The spines on the starfish's underbelly are much softer than the ones on the calcium carbonate plates, but they still make it hard for predators to get to the "meat" of the starfish.
Another defense mechanism that helps starfish flee predators is regeneration. If a hungry otter grasps hold of a starfish's arm, the starfish can release that arm, scuttle away, and then regenerate the arm. Most of a starfish's vital organs are housed in the arms, and some are able to grow a whole new star from one remaining arm, as long as enough of the starfish's center remains. This is a gradual process, though, as it takes a year for a single arm to regenerate.