If someone is feeling stuck as a coder then they can always diversify. For example, I consider myself a "frontend developer." What does that mean? It means I develop frontends. The term frontend usually applies to a website, but recently I've branched out. I have now worked on the frontend for mobile apps, VR, AR , wearables, desktop apps, and voice interaction. I didn't even learn a new programming language. If you're bored or stuck at coding one thing then branch out and look for new ways to apply your existing knowledge.
I always believed that being stuck or coming up at a dead end is a choice: That I have control over both my immediate and long term future. Whether it is in life or in my career. These days we spend at least 50% of your time - and sometimes more of that at work. We have the power to choose our course, to set our own pace, etc. there is always new tools and tricks you can spice your code up with; or new people to meet; or a course you can do to learn new things... Or a project that comes up where you work with new people or with a new product that you are excited about. Life does sometimes throw one curve balls. But when they come, you will be ready to handle them from experience you have gained. There is always someone who needs a developer. Take on projects you enjoy; and work with people you like. For me, these are lessons I have learned through my experiences. And ya... I suppose I am no longer twenty, but I guess that is both the positive and the negative in growing older :)
I'm not yet in the 40+ (being 38 as of today), but don't see myself hitting a dead-end soon. As @JanVladimirMostert mentioned, over the years you'll experience repetition of patterns and trends. The recipe I used to still be valuable and enjoy what I'm doing is trying to avoid the hype-trap and use your experience to bring value to your company for embracing new technologies that are likely to stay useful. In other words, choose wisely where you want to put your focus on, and you'll be able to be relevant and desired.
On the other end, you don't have to wait 40 to notice that our domain is evolving at such a fast pace that as soon as you have 10 years of useful experience, the additional years usually don't matter. (If you focus on a very specific domain, like pure front-end, I guess this could even be true with a smaller time span).
Technical experience you got more than 10 years ago is unlikely to be relevant today, so that's true that you might find that there's much a gap in technical expertise between a 35 years old and a 45 years old engineer. (I mean on average, we all know outstanding 25 years old boys, and older people that doesn't seem to learn anything from all ages ;-)
But technical experience isn't all the story. We work in teams, we have to forecast projects evolution and stuff like that, and that's where older smart people could bring additional value to the team.
I'm 30 and already there. My only option at the moment is going for project manager / CTO type roles, project manager roles I have no interest in and I have little desire to be the CTO of someone else's company unless I get to drive the vision of that company which is typically the CEO's role and joining another company where I'll be writing more of the same things I've been writing for the last 15 years hardly excites me.
I've started focussing on my own joint-ventures / startups as a means to get out of the rat-race, software development is no longer something that excites me to the point where I can't wait to get up to write code - it simply became a tool I use to build things and solve problems with. Seeing the big picture unfold still brings me joy (whereas the development process in the past used to bring me joy) - this does have the benefit that I can focus on extremely large projects and stick to it for very long. Maybe the next step for me is startup architect <- that excites me, maintaining someone else's code doesn't excite me. Solving complex problems still excites me, writing another login dialog and authentication system does not.
Furthermore I've seen the same cycles happen over and over again since I started programming day and night from age 15. Every year or two, something new comes along and everyone jumps on the hype wagon (I think it's called silver bullet syndrome), a few years later it gets abandoned for the next big thing. Some of these new things are truly revolutionary, others are just a different "syntax" to do the same thing, mostly I'm just seeing more of the same with different toppings.
Learning a new language is hardly a challenge anymore, as I've said before, most new languages are simply more of the same with different toppings.
I still have lots to learn, but unlike 15 years ago when it was a giant mountain to climb and climbing mountains was a fun thing to do (everything to learn), it has become a much smaller mountain to climb and there's less motivation to climb this smaller mountain unless it has immediate benefits. Example, learning Kotlin inside out has short-term benefits, I get to write less code and deliver more functionality, I see no benefit to learning Ruby (on Rails) since I won't be using it in any project anytime soon whereas 15 years ago, I would have learned it whether I was going to use it or not.
TLDR - be in the industry long enough, and you'll probably get to a point where you'll experience severe boredom, your payscale will probably start crawling towards its ceiling which further limits your options (unless taking a pay cut is an option) and your only further options are going into positions where you'll deal less with code.
I'm in my mid-40s and feel like I'll be beyond my usefulness within ten years. Not because I can't learn anything new, but because ageism is a very real thing in this profession. My entire professional and personal life is built around my development skills, so switching careers isn't really an option for me. Certainly not a fiscally viable one.
Besides age being a factor, I'm finding that my entire motivation is at an all-time low. Not burnout. I have no trouble coding for hours on end. I just don't want to anymore. I find myself doing the same stuff now that I did 20 years ago, just a different canvas and with a different language. Complacency is a real thing, too. The only solace I have is that what I'm doing does have a positive effect on other people downstream. (I'm in healthcare and built a case management system for nurses to help people with chronic illnesses.)
So, my answer to your question is, no, it's not true. But, it can be an uphill battle due to external factors.
I feel saying this would be true of almost any career - A mechanic not learning how to work on the latest engine / drivetrain / body work styles could get stuck. A doctor, a teacher, a construction worker, etc...
If all you ever do is 1 thing, sure - you could end up in a dead end. But a lot of us are self taught. So long as you don't loose that drive to continue to learn and expand your knowledge, you should be fine.
edit: I'm 36 so... this better not be true, haha. Being 36 means I learned AJS at 34. I personally don't like React (just to mention 1 new and popular framework) but I like Vue.js and am using it in a project.
I'll add also - the older you get, you might get a bit stubborn, but again, this is just a realization that this industry changes and changes fast and if you don't want to be left behind, you need to keep on top of it.
David Cresswell
Whilst I don't doubt there is a good deal of ageism around in all industries, especially one that is still relatively young itself, I have been very fortunate in being able to avoid it.
I have just turned 52, still a code monkey first and foremost and thrive on keeping up with the latest and greatest technologies. It's what I get out of bed for and hope to be able to do so right up to retirement age. What I suspect (in truth, know) I am loosing in mental sharpness I would like to think I more than make up for in terms of experience, perspective and general worldly wisdom.