Is this good or fair when it does happen? No.
Is it illegal? Sometimes, but making formal proof is daunting at best and usually not possible.
Thus, it comes down to this: treat others as you yourself would want to be treated. If a workplace reflects that ethic, it will be a place where old and young alike will want to work and where older workers will receive their due as befits their experience, skills, and performance, good or bad; if it does not reflect that ethic, it is a place to avoid if at all possible.
While Silicon Valley may represent the ageism problem in a particularly acute way owing to its youth culture, it really is no different from anywhere else. There is the good and the bad, and we each need to do what we can to uphold a high standard of common decency for ourselves and to make sure others do the same. It may not be a complete answer but it can help a lot in our immediate work environments and that will go a lot farther toward solving the problem than the law ever can.