I saw a hit from google search "why do animals molt"?
Good question. Animals have radiated into many branches, and some of them have developed a unique method of growth. By getting larger, they cast off their old skin and make a new one. Most known animals that do this are of course arthropods, to a lesser extend rotifers and nematodes, and some other groups (see here). Arthropods are animals like spiders, crustaceans and insects.
It’s a great way of regrowing damaged parts, like a torn off leg or the sort. Hard skeleton also provides places where muscles can attach. Some animals have a very hard exocuticule and makes them almost rock hard.
The downside of this method is that when you molt, you’re exposed to most things that likes to eat meat. Crabs for instance take refuge during this vulnerable period in rock crevices or other hiding places. Once they jump out of their old skin, which is not an easy task, they start taking up water so that their skin inflates. To get out of their old skin, all hard parts must be shed. This includes skin that has formed from ectoderm, which include the entire body surface, mouth, esophagus and hind gut! After they have finished, they produce a harder skeleton, made stronger mostly with calcium or some organic molecules, mostly chitin.
The process is called ecdysis, hence Ecdysozoa.
Molting of snakes is not analogous.