Stripes that are really numbers
A standard product barcode, the UPC, encodes twelve digits. The black bars and white spaces come in different widths, and the scanner reads the pattern of widths as a sequence of numbers — the bars are the digits, written in a machine-readable font.
Importantly, the barcode usually does not contain the price. It contains an identifying number, and the shop's computer looks that number up in a database to find the name and current price. Change the price in the database, and every item updates at once.
The first scan and the checkout beep
The barcode idea was patented in 1952, inspired in part by Morse code stretched into lines. It took lasers and cheaper computers to make it practical, and the first product scanned in a shop — a pack of chewing gum in Ohio — was in 1974.
That beep you hear is not the sound of the price being found. It is simply the scanner confirming it read the code successfully, so the cashier knows the item registered.
The clever last digit
The twelfth digit of a UPC is a check digit. The scanner's computer does a small calculation with the other eleven digits and compares the answer with the check digit. If they do not match, the code was probably misread and the scan is rejected.
It is a tiny piece of built-in self-checking, the same basic idea — add a number whose only job is to catch errors — that appears in bank cards, book ISBNs, and many other codes.

