In one study, published in 2015 in the Journal of Personality and Social Psychology, researchers asked several groups of participants how chaotic their childhoods were, based on measures like, “I had a hard time knowing what my parent(s) or other people in my house were going to say or do from day-to-day.” They then reminded participants about tough economic times by having them read a fake New York Times article about the recession. Next, they had them perform a task that measure their inhibition, or self control, by requiring them to not look at a flashing, yellow box. Finally, the researchers asked the participants to play a game that would measure their ability to shift quickly between tasks by categorizing shapes according to rapidly changing rules.

Across four experiments, the researchers found that when primed with economic uncertainty, people with unpredictable childhoods performed worse on the inhibition task than those from stable ones, but they did better at the attention-shifting task.

Chiraag Mittal, a professor at Texas A&M University and lead author of the study, explained that in uncertain environments, ignoring a potential threat can be deadly—thus, the subjects who had hard knocks earlier in life might have been skilled at keeping an eye on the periphery. “In an uncertain environment, where you don’t know where the next negative thing can happen, you want to be vigilant,” he said. “In a bad environment, you want to look at the light, because you want to know what it is.” And task-shifting might have behooved kids who had to, say, quickly adjust to new adults living in the house or to capitalize on fleeting and rare opportunities.

“We have been documenting deficits in children from high-stress backgrounds forever,” said Bruce Ellis, a psychology professor at the University of Utah, who was not involved with the study. “We fill libraries with all the things that are wrong with them. But this paper was the first systematic attempt to understand what was right with them.”

Switching between tasks isn’t the only cognitive enhancement that a difficult childhood can bring about. In a forthcoming paper in the Perspectives on Psychological Science, a team of researchers led by Ellis reviewed a number of studies that found boosts in various types of thinking among people from harsh or unstable backgrounds.

In one study, children of divorce remembered more early-childhood events; people whose parents were more verbally aggressive were better able to recognize emotions. “When you grow up in low-socioeconomic conditions,” Ellis explained, “there are other people around you who are more powerful than you and have more power than you, in ways that people from middle-class backgrounds don’t experience. In that context, being able to predict what they’re going to do could be very important.”