Way before xbox, this has been their strategy since before they were making video games. Gunpei Yokoi, who came up with the idea (and practically nintendo's entire electronics division), called it "lateral thinking with withered technology" (https://en.wikipedia.org/wiki/Gunpei_Yokoi#Lateral_Thinking_...).
Yup the game gear was technically better but the cost difference meant the Gameboy was more ubiquitous and so that's what sold.
Also for the switch, a lot of kids who had Gameboy's when they came out are now working and can afford a souped up handheld alongside their main console.