You are walking down a street, perhaps on an errand, when the smell of fresh-baked goods wafts your way, immediately drawing your attention to the bakery around the corner. There’s something about food, especially sugary, fatty, high-calorie food, that has the power to sidetrack us. A new study from Johns Hopkins University confirms this attraction — and advises, avoid grocery shopping when you are hungry.

Researchers wanted to see to what degree people were distracted by pictures of food, especially high-fat, high-calorie food, when they were performing a complex assignment. They created a difficult computer task and asked a group of people to complete the assignment as quickly as they could.

Even when it is irrelevant to what we are doing, even when we think we are concentrating on something else, food is distracting.

While the participants were working on the project, pictures of random items like bicycles and thumb tacks appeared in the periphery of the computer screen for 125 milliseconds, so fast that the people barely had time to register what they saw. It slowed participants down a little as they proceeded through the task, but the participants’ distraction time doubled when pictures of foods like chocolate cake, candy, doughnuts or hot dogs appeared. Images of salads, carrots or apples, however, were no more distracting than pictures of bicycles, lava lamps or footballs.

Using another group of people, researchers repeated the experiment, but this time the participants ate two fun-sized candy bars before starting the task on the computer. This group of people was not distracted by the images of junk food any more than they were by the other non-food pictures or images of healthy foods.

“I assume it was because it was a delicious, high-fat, chocolatey snack,” said co-author, Howard Egeth, a professor in the Department of Psychological and Brain Sciences, in a statement. “But what if we gave them an apple? What if we gave them a zero-calorie soda? What if we told the subjects they'd get money if they performed the task quickly, which would be a real incentive not to get distracted. Could junk food pictures override even that?”

The results show the power of food to grab our attention. Even when it is irrelevant to what we are doing, even when we think we are concentrating on something else, food commands our attention, especially when we are hungry.

“What your grandmother might have told you about not going to the grocery store hungry seems to be true,” explained Corbin A. Cunningham, the lead author. Shopping on an empty stomach can lead you to buy things you wouldn’t ordinarily purchase because they are just that much more distracting.

The study is published in Psychonomic Bulletin and Review.