The foam on top of beer (the head) is produced by bubbles of CO2 gas that rise to the surface. Elements that contribute to the head are wort protein, yeast and hop residue. Brewers design a recipe in many cases with density and longevity of the head in mind. The choices they make such as type of malt to use and what adjuncts / flavoring agents are introduced to the beer will affect the final outcome. Mash schedules and cereal grain sources both have a big influence on how long the head lasts in the glass (retention).
The amount of foam is important from both the brewer and consumer perspective. Too much foam reduces the amount of liquid in the glass. But the right amount of foam provides a number of positive advantages:
Our senses of taste and smell are intimately interwoven (see post on the science of taste). Essentially, our tongue can perceive 5 flavors; salty, sweet, bitter, sour, and umami. All other flavors are detected through nasal interaction (orthonasal & retronasal olfaction). More aroma compounds rise to the surface of a beer with adequate foam. Foam unlocks the full range of flavors of a beer.
Because of this, beer tastes different with a head of foam. Active compounds move into the bubble walls as they rise to the top of the glass. Taste is affected physically by foam through a trigeminal sensation (like the hot sensation of chili peppers). This is a physical perception. Creaminess of foam also softens the palate and therefore perception.
Many establishments serve their beer in improper glassware (the standard shaker pint comes to mind) and they are careful to fill the glass all the way to the top limiting foam to almost none. This is usually out of an invalid perception that their customers will feel cheated by receiving a glass with too much foam.
This misses a huge opportunity to better inform their customer who will ultimately feel more empowerment and satisfaction, once they understand the advantages of one to two fingers of foam at the top of their glass.
When the glass is completely filled with liquid (and no foam), the customer IS getting cheated out of the full expression of that beer by receiving it in a less than optimal glass and without a proper head of foam.
I for one, prefer to experience each beer the way the brewer intended.