Ants release chemicals when they die that attract other ants, to fight off the threat. This is annoying, because squishing an ant that bit you is likely to attract more bitey ants.
Do ants have a chemical signal for “all ye who enter here, either turn back or abandon all hope”? Can you teach a hive to fear a certain place? Or do they just keep coming forever?
This is a beautiful and clever question, and the answer is: Yes.
Ants are able to learn to avoid places where something bad happens. In the following study, people tried to teach ants not to follow their own pheromones with positive meaning by giving them electric shocks (evil crazy scientists). They were able to teach them to ignore the signals (not to avoid them altogether though). It’s kind of a big deal, because these pheromones are normally telling them to follow them, so for the ants not to obey that is a big behavioral change.
It also tells us that electric shocks are efficient agaist ants 😉
https://journals.biologists.com/jeb/article/224/11/jeb242454/269004/Hard-limits-to-cognitive-flexibility-ants-can