In general, this is no problem. The country may have environmental laws governing the recycling and disposal of electronics, which a tourist would have to comply with, but assuming they are disposed of properly, there is no problem, because most countries do not make any record of the typical electronic devices carried by tourists. If you didn't register the goods with customs on the way in, there's no way they know or care whether you're taking them out.
Occasionally, some countries will be concerned about whether you're really planning on taking electronics back out with you, as you would be required to pay duty if the goods are imported. If this applies to you, you'll usually know about it, and it generally applies to valuable technical articles or excessive quantities of electronics (usually think professional broadcast gear or an unusual number of laptops, not just the typical laptop/smartphone/camera carried by a tourist). Such goods could be covered under the ATA Carnet scheme, which obliges you to re-export the goods within a year or pay the applicable duty. Without a Carnet, the country could impose a deposit or charge import duty, and you'd have to use whatever mechanism exists in that country to get a refund when you export the goods.
If any of that applies to you, and again, it would not as a typical tourist in most all places (if you're going to, say, North Korea, there may be more scrutiny), throwing the goods away would mean that you wouldn't get your deposit back, because you're required to export the goods to do so. If this is the case, you'd likely need to hold on to the broken electronics.
In short, unless the goods underwent some kind of special registration when you imported them, nobody is going to know or care whether you export them or throw them out.