According to the Companion Animal Parasite Council, puppies and kittens need to be dewormed every two weeks until they are two months old, then put on a monthly prevention for the rest of their lives. The monthly prevention is part of most monthly heartworm preventatives, so you don't need to woory about giving something extra for parasites.
Other deworming medications should be given as needed when worms are found. Puppies should have their stool checked at least once when they go to the vet to get their puppy shots, then every 6-12 months for the rest of their lives.
The response of the worms to the medication depends on what type of worm, but I'll use roundworms and hookworms as an example since they are the most common:
When the first dose of dewormer is given, it kills the adult worms more or less right away. They are then passed over the next couple of days in the stool (although most people do not see them unless there is a really big parasite load). However, the dewormer doesn't affect any of the immature worm stages that the puppy might also have ingested within the previous two weeks. So a second dose of dewormer is given two weeks later, after the immature worms have become adults and able to be killed by the treatment.
Puppies are very susceptible to worm infections, so they may get reinfected after treatment. Also, the dewormers are only 99% effective. That means 1% of puppies need more than two doses to get rid of all the worms - especially if there is a very large worm burdern. This is why it's important to have the vet recheck a stool sample 2-4 weeks after treatment, to make sure the deworming was effective.