It can protect against losing body heat. This is thought to be the basic, original function of hair.
It protects against UVradiation, which damages the skin.
It can protect against rain or water. Air can be trapped in the fur, or oil can be secreted by the skin. Both these methods prevent the rain or water from making the body too cold. Aquatic mammals in cold waters usually have blubber (fat) under the skin, and almost no hair.
Defence: hair is modified in mammals like porcupines, for protection.
Hair colouring can perform different functions. It helps to camouflage in some animals, and to signal to others of the same species in some other animals. Examples are: signalling to females for mating purposes and signalling to others for territory control. Signalling danger to other species (aposematic colouring) is also done by, for example, skunks.
Animals can change their hair so they look bigger, or more threatening. This can also be used for mating; which is the case with lions, for example. Also, the male lions' mane also protects their neck from damage when fighting other males.