Piping Hot, Ice Cold... Thanks to Chemistry

Self-heating and self-cooling cans allow you to heat or cool your food in a few minutes. How do they work?