Popular belief is that candies are bad for teeth because of the sugar. The reasoning being that the sugar is converted to acid by oral bacteria, and the acid corrodes tooth enamel. However, this reasoning is wrong.
It is true that the lactobacillus bacteria commonly found in digestive systems converts glucose to lactic acid as part of their glycosis metabolism. This process is leveraged by cheese making, where the acid produced by these bacteria causes the casein in milk to curdle. However, the rate of lactobacillus glycosis is very low, and saliva secretion which is slightly basic would quickly neutralize and remove any acidic byproduct, so the resting pH of mouth never falls below pH 6.3. The critical pH for enamel erosion is 4.5 or below. That means the oral fermentation of sugar as a theory cannot explain tooth decay.
However, we do know that candies, particularly hard candies and gummies, contain citric acid for flavoring. These sour candies stay in the mouth for a long period of time, and citric acid can have a pH as low as 3. That means just by keeping sour candies in mouth will directly corrode the teeth. Some sour candies can have pH as low as 1.6.
Flavored beverages can be harmful in the same way because of its citric acid content, but it doesn’t stay in the mouth long enough to cause significant corrosion. This is the same with eating acidic food such as oranges. Even though fruits can have pH as low as 3, it doesn’t stay in the mouth long enough to corrode, and the remnant is quickly neutralized by saliva.
Chocolate is slightly acidic, having pH as low as 5. But this is not as bad for enamel.