The way moths are attracted to light is actually really interesting. The behavior is called phototaxis, positive phototaxis to be specific, cockroaches would be an example of negative, their reaction to light is to seek darkness as a way of avoiding predators. The leading theory is that they do it as a means of navigation. The majority of known moth species are nocturnal after all, and when they usually fly around the moon is their guide. They use the moon as a point of reference so that they’re able to fly in a straight line by maintaining their angle towards the source of light. However, they aren’t able to distinguish the moon from an artificial source of light, like a lamp. This leads to an interesting kind of situation. When they use the moon as a reference, the moon’s position is consistent in terms of their field of view. The same isn’t true with a lamp because it’s a lot closer. Therefore, the moth uses the lamp as a reference, flies, sees the, “moon” has moved in their vision, assumes that they’ve accidentally flown off course, so they correct themselves, only to see the, “moon” change its position again. This process continues, the moth keeps turning towards the lamp, constantly correcting their angle. In real time this results in a spiraling flight path that gradually gets closer and closer to the source of light. Sadly, the moth often ends up hitting the source of light, zapping or burning it to death. The process is hardwired into the moth’s neurology, there is a tiny but distinct clump of neurons in many species’ brains that guides it, this clump is humorously called the, “Icarus cell.”