I think it can be location and company specific too. In some cities hiring is hard to do, so they take what they can get. And some company cultures value experience and stability, others like younger devs.
My experience has been that most devs in their 40s and 50s can run circles around those in their 20s and early 30s. If someone is already good in their 20s they're likely a savant. TL;DR the biggest thing is managing your career intelligently. I think there's more risk when you approach 50, but the same is true in every industry.