Literary devices aren't just for English classes. Foreshadowing is a powerful technique that can enhance your plot, add substance and intrigue and bring closure to the story; it's the full circle connection in really good books that makes you go "whoa, cool". But foreshadowing relies on subtlety and unobtrusiveness. Therefore, avoiding being obvious is essential.
Let's follow J. K. Rowling's example, who is, unsurprisingly, is a master of foreshadowing and at linking plot devices in later books to objects mentioned in early books. Although some of her later connections could be the result of an excellent memory, such as how Harry's knowledge of the bezoar from The Philosopher's Stone is used to save Ron in The Half-Blood Prince, she also creates connections within books that are almost indubitably foreshadowing. Take, for example, in The Chamber of Secrets, Ron's comment about why Tom Riddle could possibly have a trophy with his name on it:
'Could've been anything,' said Ron. 'Maybe he got thirty O.W.L.s or saved a teacher from the giant squid. Maybe he murdered Myrtle; that would've done everyone a favor...' (p. 251, Raincoast Books paperback edition)Ron's joking, of course. But at the same time, he's right: Tom Riddle was the one who opened the Chamber of Secrets, let loose the Basilisk and killed Myrtle in the bathroom she now haunts. This innocuous piece of information, dressed up as a (somewhat mean-spirited!) joke, becomes a clue which later reveals itself to be the key to the mystery that dominates The Chamber of Secrets. And because the truth is framed in a sidenote-style comment, it works.
This sidenote approach is a very good way to think about foreshadowing. You're not coming right out and saying "this is important, remember it!!11!"; instead; your hints are casual observations about setting, character or events that could be innocuously taken... or could mean something more.
Straddling the line between "innocuous" and "obvious" can sometimes be tricky. As a book reviewer, I've grown to gauge the amount of attention paid by the narrator or narration to any one certain object or event. Oftentimes, foreshadowing is clunkily done when the author takes one too many sentences to point out an item that will be important; this sets off alarms in my head that say, "This will be important later on!", like foreshadowing for dummies. Not what you're trying to achieve!
Therefore, it's important to slide your clues among like-sentences. As shown above, Ron listed a series of reasons why Tom Riddle would have won the trophy. If your middle-grade mystery's real culprit is someone who chews a lot of gum, let's say, have your protagonist note the amount of gum wrappers around the scene of the crime in context with something else—maybe they like to be environmentally conscious.
After you've set up your hints, it's important to make good on them in the right way. J. K. Rowling didn't ever have Ron say, "Oh, wait, I was actually right!" at the end of The Chamber of Secrets. Rather, letting the reader realize on their own how the reveal was set up spurs that "cool!" feeling. It also can bring closure; linking your book's end back to its beginning brings your story full-circle and gives it resonance.
How do you use foreshadowing in your writing? What do you think of foreshadowing as a writing technique?