An answer on another SE site mentions that sugar "at a certain level acts as a preservative". I've always been taught that microorganisms eat sugar and expel acids, that is why sugary food are damaging to teeth. How is it that sugar acts as a preservative, then?
Sugar in high concentrations acts osmotic. This means that the water available in the cells is drawn towards the high concentration of a solutant (sugar), like in the image below (this is demonstrated with a plant cell, but the principle is the same for bacteria and other microorganisms):
Since microorganisms can not survive without water, they are not able to grow or reproduce. This effectively safes food. The same mechanism works when salt is used to conserve meat or fish.
Sugar participate in food preservation only at high concentrations. When microbes are introduced to high sugar concentrated environment, water inside the microbial cell diffuses out to the high sugar concentrated solute due to the phenomenon called osmosis. As water is very much needed for cell functioning and metabolism the dehydrated cells fail to perform its function and eventually die. This is called sugar curing, a food preservation technique. Also hard sugary sweet is less susceptible to microbes than soft sugar sweet because of its high sugar content that makes it intolerant for microbial growth and also the absence of moisture (important factor for microbial growth) in the hard sweet as compared to soft sweet makes it less susceptible to microbial attack.