The best way to play against traps is to know them, but that is not possible every time. The second best way is to check the consequences when you have been offered some bait and check the variations in details. This requires good calculation skills and beginners or kids might not have this. Don’t worry as there is one more way to avoid them, and that is to use soft reasoning.
First of all, most of the opening tricks and traps are based on the key opening principle of fast development. For example Legal’s mate involves a queen sacrifice (the bait) and White checkmates with three minor pieces against Black’s only developed piece, the light square bishop on d1. My point is that even if you are not able to calculate thoroughly you can use this sort of soft reasoning to avoid such pitfalls.
Here is an example from real game of mine. My opponent was a 2100+ rated player and had the White pieces.
1. e4 d5
2. exd5 Nf6
3. d4 Nxd5
4. c4 Nb4 ?!
By playing Nb4 on move no 4. I invited White to win a piece with 5. Qa4+ Nac6 6.d5. This is a very cunning trap and my opponent played a3 instead, which is the best move and gained a good center. Later on I asked him whether the trap was known to him and to my surprise he didn’t know it, but he simply rejected the trap based on following reasoning:
White’s only developed piece would be the queen compared to two knights (knights on b4 and c6 after Qa4+) and if he tries to win a piece with pawn to d5 Black can develop a third piece. So he simply rejected Qa4 and smelled something was not right.