Using the mosquito as an example, there is a chemical called DDT which a number of years ago was very effective in killing mosquitos however there was a very small percentage of the population that was immune to this chemical, as a result of genetic variation, and this population survived and passed this favourable characteristic onto their offspring and within a few years, most of the population of mosquitos had a resistance to DDT as those who didnt died.