Would a quality derailleur improve a cheap bike I bought my son a cheap mountain bike last week, it did 2 miles before the chain mashed up the drailleur. is it worth replacing with a better quality component. im a novice , but handy enough to upgrade. he loves the look of the bike but my question is , is it worth the effort..
If your bicycle is a BSO (bicycle shaped object sold at discount mass retailers), then likely no. You'd spend $100+ labor on the derailleur and a new chain, but then the next week the brakes would fail,  the handlebar would come off, or the frame would crack. BSOs are money pits. Furthermore, it's unlikely you could just replace the derailleur, you'd have to also buy new shift levers or brifters, depending on what you're replacing it with. If the derailleur ate the chain, then it's likely that the derailleur hanger will also be bent or misaligned.  I'd use the return policy of the store to return the bike. It was clearly misassembled.

If your son's bike was a quality used bike (like a late 1980s hardtail Specialized Rockhoppper)  then it's likely that the "bones" are good and that upgrading some components would be worth your while. A better derailleur would lead to faster and smoother shifts. But you'd still run into the problem that by the time you get new derailleurs and shifters, you might have spent enough to buy a used 2000s Trek mountainbike. There's plenty of life in the older hardtails and many people prefer them to the newfangled things.



Update:  A store return isn't possible as it was bought off of the street and that the owner has £85 in sunk costs for a bike that would be about £130 new -- i.e., a little bit above a £50 BSO but not yet into the middle end. With £85 in sunk costs, I think you want to keep your repairs to under £25 given that you already spent a bit on a new tire and tube.

The likely thing that happened is that the old derailleur's high or low-limits were not set correctly. Thus when your son unknowingly shifted up or down (likely up), the chain skipped merrily off the rear sprockets into either axle (from the highest -- i.e., smallest-- gear) or the spokes (from the lowest). This then jammed the rear wheel, yanked the derailleur into bits, and it's lucky your son didn't have an accident.

First, you need to assess the damage. The rear derailleur is mostly probably bent/broken beyond repair (while tempting you cannot unbend it). Check the chain carefully, it is likely to have some bent or damaged links. Check the rear sprocket, are any of the cogs damaged? Check the spokes if the chain damaged them. Check the derailleur hanger, is it still straight? Check the front chain ring and derailleur, do they look good? 

If you're lucky, the damage is just limited to the rear derailleur and to the chain. If the chain appears to have any damage at all, it's safer to get a new one (a bend in the chain or kink will cause chain suckage again). 

The problem is finding a new derailleur. You want to keep the old shifters if possible to save money. There are two factors: one is the number of gears (7/8/9) on the rear and the second is the shifting mechanism. If you want to DIY, then you could purchase a new rear derailleur (assuming you have a 7-8 cassette on the rear, they go for around £10-20 for the cheapest models, but again make sure it's compatible with your shifters). Then look online for detailed instructions and be sure to set the hi/lo limits on your derailleur correctly -- and make sure your derailleur hanger is straight.

If you need a new chain, then you'll need to get a chain breaker tool as well, so budget that in. Other tools you may need will include a set of hex keys (allen wrenches), screwdrivers, adjustable wrench, bandaids (for skinned knuckles), pliers (to crimp the ferrule of the derailleur cable, don't forget to get some ferrule caps), and a BIG adjustable wrench if your derailleur hanger is bent.

Again, it's not trivial to install and adjust a rear derailleur correctly and not really a project for a brand new bike mechanic, especially when the test subject is your son. 

Otherwise...

Find a local bike store that appears to have been around since the time of the Wright Brothers. The greasier the better.  Go to it with your tail between your legs and ask if they might have an old, used derailleur that will fit your bike. Do not wear nice clothes when you go. Bring your son and have him make puppy dog eyes.

If your store is anything like the place that I have downtown, then they can dig out an old, compatible derailleur from their parts bin for £3 (US$5) and might even put it on for you for a few quid more. Be sure to patronize them in the future.