I think it's fair to say this skill difference is largely from that work in the C family, where I learned a number of different paradigms for design and development in that world, with all its footguns and low-level "gotchas". It has always been easier for me to parse and understand others' code, identify subtle bugs, to use debugging tools, and to identify some optimizations by examining the code that others might spend days using profilers to find.
Some of that would come with engineering experience in general, regardless of languages used, but not all of it, but I picked these skills up faster and earlier in my career, thanks to that early work. Skill with C++ is definitely transferrable, in at least some cases.
In that case, if web development is your interest, then you have many possible paths.
The primary choices are full stack, backend, or frontend.
Obviously full stack is most flexible because you can theoretically do it all. But keeping up with so many technologies simultaneously is really tiring.
Take a look at Phoenix framework. It is a fantastic way to get started, and it will grow with you into just about any future project need. Plus Elixir is an excellent language built on top of the incredibly powerful Erlang ecosystem.
I'm sure he could learn STL (standard C++ library) in a fraction of time it would take someone else to become proficient in C++ in general.
Even in a bad code base you can start making things better, apply modern techniques and learn new things.
Also most of the skill you gain there is transferrable. E.g. just because you have to work with some legacy PHP project, it doesn't mean that you would suck at creating modern applications in JS. It would just take a couple of weeks to get use to it.
All th bad codebase I've seen were a result of fossils who are still with the company gatekeeping anyone from fixing their code.
A few years ago, I had one architect stubbornly refuse to use source control, rejected all PRs that didn't use his homegrown buggy C++ libs for strings, refused to let anyone do the http server bits unless they used his C++ server and so on.
If there isn't a gatekeeper, you wouldn't have the bad codebase in the first place.
I disagree; working on a legacy PHP project isn't just opportunity cost (failing to sharpen your knife), it's actively harmful (leaving the knife in salt water, accelerating the rust).
My mother was a COBOL developer and didn't work for 20 years because she stayed home. She recently returned to her old bank she worked for because they are dragging people out of retirement as they can't find anyone else. She earns more than I do now.
People are crazy to give a job like that up for generic web dev work.
Start saving now.