Except in the cases of infant formula, and some baby foods and dairy products, the process of dating foods is a voluntary one. As such, the process varies from company to company. In fact, they're not even real "food expiration" dates, per se, but just an indicator of when the food is no longer at its peak freshness.
Most foods are safe to eat after their date, but determining safety is then on the consumer. In fact, it is estimated that up to 90 percent of Americans annually toss out edible food, wasting up to 40 percent of the food supply, several hundred billion dollars worth of food.
Companies determine their dates by having experts come in and analyze the texture, taste and smell of stored foods in various conditions. Needless to say, there is a point in the decay curve of every food where it gets noticeably less fresh and appealing, and this happens before the food is actually unsafe to eat. It is at these drop-off points that the sell-by/use-by/best-by dates are assigned.
So, no, not a scientific process. The tests are done scientifically, but the end calls are very subjective, and the dates exist so that their products are either sold or pulled before a consumer buys something that's not that tasty.