For many animals, their other senses come into play.
Just like us, animals will looks at color, condition, smell, etc..
They evolved to avoid things that are dangerous. The animals that had mutations that made a rotting carcass smell bad are the ones who had a lower chance of getting sick and dying which leads to a higher chance of passing on that gene.
Same thing is true for berries, fruits, plants, etc..
It’s not so much that they know they’re bad as much as they know that there is something off-putting to them that make them not want to eat it.
Latest Answers