There's been a lot of fluctuation in the stock market in recent years. The COVID-19 pandemic sent many stocks skyrocketing in 2020 and 2021 as lockdowns led to increased spending on tech and home entertainment products. However, macroeconomic headwinds in 2022 brought the market crashing back down, with countless companies losing what they had gained the year before.

In 2023, stocks have once again swung in the opposite direction. Easing inflation and excitement over high-growth industries like artificial intelligence (AI) have allowed for a recovery, with the Nasdaq Composite index up 36% since Jan. 1.

^IXIC Chart

Data by YCharts

Recent volatility has had many analysts at odds on whether this is a bear or bull market, with varying definitions for both terms. However, the more standard definition of a bear market is when the market declines 20% from its previous high. Meanwhile, a bull market hasn't returned until it rises above that high. The chart above shows the Nasdaq entered a bear market in 2022 and has yet to see another bull market.

Alongside residual fears of a recession next year, now is an excellent time to get familiar with some of the best stocks to buy if the market takes a dip. Here are two stocks I'm buying in a potential recession.

1. Apple

Apple (AAPL -0.35%) is one of those stocks that rarely goes on sale. Its position as the world's most valuable company, with a market cap of $2.9 trillion and a stock price that rose 335% over the last five years, has created loyal investors that tend to buy or hold during challenging times.

For instance, in 2022 the Nasdaq Composite plunged 33%. Yet as the chart below shows, Apple was among the few big tech companies to outperform the index, along with many of its competitors.

AAPL Chart

Data by YCharts

This year Apple has faced repeated declines in its product business, with revenue dipping 3% year over year in its fiscal 2023. Poor economic conditions curbed consumer spending across the tech industry and hit some of Apple's highest-earnings segments. However, the company's reputation for reliable gains over the long term has seen its shares climb 46% since Jan. 1.

Loyal investors will only take Apple so far, and are not a compelling enough reason to buy. However, it does instill some reliability in its stock during temporary headwinds.

Meanwhile, the company's solid financials and prospects in multiple lucrative markets could take it far in the coming years. Despite declines in its product sales, Apple's free cash flow topped $99 billion this year, suggesting the company has the funds to overcome current hurdles and continue investing in its business.

Alongside a booming digital services business and a gradual expansion in AI, Apple's stock is a no-brainer in a bear market.

2. Costco

As one of the world's biggest retailers, Costco's (COST 1.01%) business is vulnerable to economic fluctuation. However, its unique model of selling wholesale items at market-low prices for the cost of an annual membership has won over shoppers worldwide and granted the company stellar long-term growth. As a result, a recession could be the perfect time to fill up on Costco's stock while it's temporarily down.

COST Chart

Data by YCharts

The table above shows Costco's stock has climbed significantly higher than those of most of the biggest U.S. retailers since 2018. Also, its shares delivered a more consistent rise over that time rather than the deep peaks and valleys some of its competitors experienced.

In addition to reliability, Costco's latest quarterly report indicates it could be on a lucrative growth path heading into next year. In the fourth quarter of 2023, Costco's revenue rose 9.5% year over year, beating analysts' expectations by more than $1 billion. The company posted a 4% spike in international income, a segment with massive growth potential.

Costco operates 870 stores across more than a dozen countries and is expanding rapidly as it opens about 25 new stores annually. The company's business has proven its ability to traverse continents and cultures, succeeding in almost every new market it enters.

In fact, Costco ventured into China for the first time this year, and already has five locations in the region. The retail giant has barely scratched the surface of its international expansion and will likely continue seeing big gains over the long term.

Over the past five years, Costco's revenue soared 125%, with operating income up 193%. The company is one of the best long-term ways to invest in retail, and an attractive option during an economic downturn.