Developers also switch jobs to get more salary and market themselves as specialists in a specific stack.
I yet have to see developer taking pay cut to retrain in a different tech.
Companies already have to factor in training of people on their company specific stuff. That is why no one expects new hire to be fully productive in first 3-6 months. Even if you know JavaScript it still is quite a lot of work to understand code base ... now take someone who does not know JavaScript and as addition has to learn company specific stuff.
That is why hiring is like that because "tech" is transferrable skill between companies and developers like to invest into transferrable skills.