The stationary ones used to have a spinning mirror with a laser pointed at it. You used to be able to look in the machine and see it. Dunno how they do it now for the handheld scanners. Smaller mirror or some other trick like piezo?
Hand scanners for a while have been able to use just LEDs to illuminate the barcode it turns out. Way cheaper than having so many moving parts like the older laser based scanners.