In general it doesn’t; most things that are bad for us to eat (e.g. feces) also taste terrible.
Unscrupulous junk food companies take super-cheap food that people would normally know better than to eat, and carefully engineer it to taste good so that they can sell it to us anyway. (Usually by adding a bunch of salt, sugar, and fat, as other posters have described.) But that takes a lot of effort: the result tastes good *in spite of* being made mostly from garbage, not *because* it’s made mostly from garbage.
Admittedly, our ancestors evolved in a time of relative scarcity, so we’re wired to eat more than we should. So some stuff can be bad for us just because it’s “too much of good thing”. But I think you were asking mainly about unhealthy *types* of food, not unhealthy *quantities*.
Latest Answers