You can make a 2x2 matrix with "legacy code quality" on one axis, and "language percieved desireability" on the other axis.
You can make truckloads of money, earn much respect, with nearly zero negative ageism, in at least one of those quadrants.
"Building new" versus "maintaining existing" are different mindsets, and often a choice.
For older people just getting started, "maintaining existing" is often the wiser first decision. From there, the particular mix of language and tech stack count, and often the more obscure the better.
Find a good niche.