Stocks may be well up from their March lows, and in many cases are trading at record highs. The fact of the matter is, however, we're in a recession. The second quarter's GDP contraction is on the order of 30%, and while unemployment has somewhat pulled back from its April surge, the nation's unemployment rate remains at an uncomfortably high 10.2%.

That doesn't necessarily mean stocks are doomed, though. It simply means investors would be wise to consider the macroeconomic environment and apply a little strategy. Some companies will hold up against the recession headwind, and others may actually thrive because of it.

Here are five stocks that are still perfectly fine to own despite the recessionary backdrop we find ourselves in right now.

Man pressing a "buy" button on a computer keyboard

Image source: Getty Images.

1. Walmart has it all

The world's biggest retailer is the biggest for a reason, and that size certainly provides Walmart (WMT -0.35%) with an edge that smaller players can't match. But that's not the key reason to stick with Walmart right now. The key reason the company will be fine is that low-priced consumer staple products and groceries aren't subject to the same spending cutbacks that luxury goods and travel plans are. Consumers always need staples like detergent, towels, and school supplies.

One only has to look at last quarter's results for Walmart to appreciate this. While the coronavirus pandemic was in full swing during this timeframe, Walmart managed to improve its top line to the tune of 5.7%. Operating income grew more than 8%. Clearly, the company's got what people want, or need.

2. Apple fosters loyalty by enhancing stickiness

Whereas Walmart is a top pick during tough times because it offers consumer staples, consumer-tech giant Apple (AAPL -2.19%) makes the grade for the exact opposite reason. That is, it's a bulldozer. Consumers want its products so badly that a recession doesn't stop Apple fans from buying its wares or using its services. For its quarter ending in June, the top line was up 11% year over year. Not one of its five reporting units (iPhone, Mac, iPad, wearables, and services) posted weaker year-over-year or year-to-date results for the quarter in question. It's a testament to how well its strategic shift is working.

Apple likely knows its product saturation point is on the horizon, if not in the rearview mirror. The company is driving growth, however, by enhancing its digital ecosystem that makes its hardware ever more useful. Services revenue grew 15% as Apple sold more apps, movies, and music. The recent deal with ViacomCBS to offer Apple TV+ subscribers a discount on the media powerhouse's CBS All Access and Showtime streaming products illustrates how the organization continues to make its products stickier. 

3. Can't quit Microsoft now

Tech giant Microsoft (MSFT -1.96%) makes the safe-in-a-recession cut for yet another reason -- it's too entwined in too many organizations' IT and cloud operations for them to sever those relationships just for the sake of saving a few bucks. Migrating to new systems is not only expensive, it's time-consuming. The recession could be over by the time that task is completed. That's how the company's all-important intelligent cloud business grew 17% during the most recently completed quarter, led by continued adoption of its popular Azure cloud-management platform.

That said, Microsoft has something of an ace up its sleeve to drive fresh growth going forward. It's been making inroads with smaller businesses at a time when those smaller businesses are increasingly wading into e-commerce. In the meantime, it's also chipping away at Alphabet subsidiary Google's dominance of the search engine advertising market. StatCounter Global says Microsoft's Bing now fields 6.2% of North America's internet search queries. It's still not a lot, but it's a marked improvement in the 5.8% share Bing enjoyed a year ago.

4. Clorox is so much more than just bleach

Few companies have garnered as much attention as Clorox (CLX -1.02%) has in the midst of the COVID-19 pandemic. It's the company behind coronavirus-killing, bleach-based cleaning products that use the same name. CEO Benno Dorer has already warned consumers that Clorox-brand disinfectant wipes could remain tough to find until next year.

It's not the sharp spike in demand for the company's sanitizing solutions that makes Clorox such a strong holding in the present environment, though; demand for those products will eventually subside. The company is a compelling investment in tougher times because of everything else it sells. Clorox is the parent for brands like Kingsford charcoal, Fresh Step kitty litter, and Liquid Plumr, just to name a few. Those are consumer staples that have already fostered a lot of brand loyalty that can withstand a temporary jump in tightened purse strings.

Of course, it doesn't hurt that Clorox makes a point of fostering that brand loyalty that encourages repeat purchases.

5. Dollar General wins by being the un-Walmart

Finally, add Dollar General (DG -2.09%) to a list of stocks to safely own despite the onset of a recession. As it turns out, there's room for Walmart and a couple of smaller retailing rivals if those competitors are doing something different with how (and where) they sell the same goods.

Walmart's strategy is clear: Dominate the consumer goods market wherever one of its stores is found. It operates more than 3,500 supercenters and nearly 6,000 Sam's Club warehouse club stores in the U.S. alone, averaging around 180,000 square feet in size. That much space means the company has plenty of room to offer everything a shopper could reasonably want.

There's a downside to that sheer size, however, that Dollar General is able to capitalize on. Dollar General stores may be smaller and offer less selection, but they can offer a shopper the absolute daily must-haves with far greater ease. CEO Todd Vasos commented earlier this year that three-fourths of U.S. residents live within seven miles of a Dollar General location, and the company boasts that its smaller store footprints mean the average shopping trip can be completed in less than 10 minutes. Convenience still counts for something.

That said, it would also be wrong to not point out that Dollar General's deep discount strategy has even greater appeal in a poor economic environment. If the recession lingers, that's what could easily develop.