From an evolutionary standpoint, the immune response that causes allergies doesn’t benefit the individual, but all of us having an immune response capability benefits the species.
When toxins, parasites, virus or other diseases attacked a population of early humans, the percentage with the best immune response survived. Now we have some humans with overactive immune systems.
More in depth reading here: https://www.scientificamerican.com/article/dear-evolution-thanks-for/
Latest Answers