In 2022, macroeconomic headwinds dragged down the Nasdaq Composite index by about 33%. Inflation hikes caused pullback from consumers and repeated declines in the quarterly earnings for countless companies.

Despite the challenges, last year was one of the best times to bulk up your portfolio, as stocks in many of the world's most valuable companies were essentially on sale. Those who invested amid the sell-off will have profited from the near-30% rise in the Nasdaq Composite index since the start of 2023. As a result, it's a good idea to become familiar with some of the best stocks to buy in the event of a market downturn to make the most of your holdings. 

So here are three top stocks to buy if there is a market pullback. 

1. Apple

Apple (AAPL -0.35%) has gained a reputation on Wall Street as one of the most reliable stocks. The company was one of the few to beat the market last year, with its stock falling a more moderate 27% throughout 2022. Consistent demand for its products and services kept it profitable even while its competitors faltered.

However, economic headwinds have caught up with Apple this year. The company reported sales declines across its product lineup in the third quarter of 2023. Yet it has continued to outperform its peers amid poor market conditions.

A study from Counterpoint Research shows smartphone shipments fell 24% year over year in Q2 2023. The declines saw Samsung and Motorola sales tumble 37% and 17%, respectively. However, Apple experienced decreased sales of 6% in the same period as its market share increased from 52% to 55%. Apple's Mac lineup similarly outperformed companies like Lenovo and Dell despite overall PC shipment declines.

Apple's dominance across tech has kept its stock consistently rising over the long term and meant its shares don't often go on sale. As a result, a market pullback is the perfect time to invest in this tech giant and benefit from its expansion into high-growth markets such as artificial intelligence (AI) and virtual reality.  

2. Costco

Costco (COST 1.01%) shares have risen 142% over the last five years, significantly more than U.S. competitors like Walmart and Target. The company has proven itself as one of the best growth stocks in the retail industry, with its annual revenue rising 60% since 2018 and operating income up 74%. Investors have taken notice, as Costco's stock is rarely trading at a bargain, with its price-to-earnings (P/E) ratio often hovering around 35 to 40.

The company's history of reliable long-term growth makes it an attractive investment during a market pullback. Its international presence is made up of nearly 860 Costco locations in 14 countries across the globe, with plans for further expansion.

In six of those countries, Costco operates four or fewer locations. As a result, the company retains massive growth potential in multiple regions. In France alone, Costco runs two stores, with plans to open 15 units in the European country by 2025.

So if you're looking for a solid retail stock to hold for the long term and a sell-off has brought down prices, Costco is an excellent option.

3. Amazon

Amazon (AMZN 3.43%) has become a favorite on Wall Street this year, with its stock up roughly 60% since Jan. 1. The growth is in stark contrast to its 2022 performance, when its stock plunged 50% in a 12-month period. Macroeconomic headwinds brought steep declines in its e-commerce earnings and dragged down its stock. However, this year's recovery has shown why Amazon is one of the best companies to invest in during a market pullback.

Despite the recent rally, Amazon's stock remains 28% down from the all-time high it achieved in July 2021. Meanwhile, a steadily improving e-commerce business and expansion into AI give it a promising long-term outlook. 

In Q2 2023, Amazon's highest-earning segment, North America, hit $3 billion in operating income after reporting losses of $627 million in the year-ago period. The improvement represents the second consecutive quarter of profit increases for Amazon's retail earnings, with easing inflation likely to keep the segment growing.

Moreover, Amazon is home to the world's biggest cloud platform with Amazon Web Services (AWS), which could be a massive advantage as it expands into AI in the coming years.

Amazon's performance this year has proved its resilience and ability to strategically restructure its business amid economically challenging conditions. The company's stock is an excellent option during a market pullback, but also right now, before its shares rise any higher.