Sound two notes a hair apart and you don't hear two notes — you hear one note that THROBS, swelling and fading, and the throb slows as the two pitches close. That pulse is the beat, and its rate is exactly the gap between them. It is how a piano tuner works: chase the throb to zero and you are in tune. Slide the two pitches, tap PLAY, and hunt the silence of unison.
Add two sine waves of frequency f₁ and f₂ and trigonometry gives one wave at the average pitch (f₁+f₂)/2 inside an envelope that swells at the DIFFERENCE — so you hear |f₁−f₂| beats per second, computed and drawn live as the pulsing envelope, and sounded through Web Audio. Slide the pitches together and the beat rate falls to zero at unison — the exact, real basis of tuning by ear.
Pure sine tones and a linear (no-distortion) ear are assumed; real instruments have overtones that beat too, and loud tones add nonlinear combination tones. The beat-rate law |f₁−f₂| and the drawn envelope are exact.