Shaking an unopened can of soda causes bubbles of carbon dioxide gas (CO2) to cover the inside walls of the can. At some point we all have had or seen someone with a can that exploded as it was opened.
When you open a shaken can, the pressure in the liquid drops quickly and all the bubbles or so dioxide gas bubbles increases instantly. And it shoots out everywhere! The quickly expanding bubbles force any liquid above them out of the can as a foaming mess.
The myth is tapping the top of the can before opening it prevents this mess. This doesn’t work as the bubbles on not on the top of the can. The science is to dislodge the bubbles from the side walls and bottom of the can so they can move to the top of the liquid (because gas is less dense than a liquid). Once the bubbles are at the top of the can, there will be little or no liquid blocking their escape when you open it. As a result, the soda doesn’t spray all over. So next time one of your friends tries to get you by shaking the soda can, just tap, tap, tap and you will be good.