About 12 years ago I was working for a PC Magazine competitor when they cut the Managing Editor loose, a man who'd worked there 20+ years and was in his late 50s. I ran into him in the bathroom, tears in his eyes, asking me what he was going to do now? That this is how they reward decades of loyalty? Ironically that magazine, dedicated to predicting future technology trends, would go down the toilet some years later…
"Companies have no loyalty folks...neither should you." That's a broad brush to paint with; companies are just a group of people, not some inhuman construct. People make the decisions and just like every other aspect of life, some people care don't put their impact on others first, or can't because of circumstances. Not every company discards employees like garbage, and it's a lousy narrative to propagate.
IBM, Oracle, Apple, Microsoft, you name it. All of those have done large cycles of layoffs.
And the coding industry is infamous for its Ageism.