A sell-off brought the Nasdaq Composite index down 33% in 2022, with countless stocks affected. However, the same index has surged 13% year to date, illustrating the importance of holding stocks over the long term through the highs and especially the lows.

For instance, those who sold Warner Bros. Discovery's (WBD -2.25%) stock as it fell over 62% last year would not have benefited from its 59% rise since Jan. 1.

As Wall Street mogul Warren Buffett believes, "If you aren't willing to own a stock for 10 years, don't even think about owning it for 10 minutes." The famous investor used this strategy to grow his holdings company Berkshire Hathaway's portfolio to an asset worth $331.07 billion.

Here are three top stocks to buy for the long haul. 

1. Apple

As the world's most valuable company, with a market cap of $2.52 trillion, Apple's (AAPL 0.71%) stock has a reputation for offering substantial and consistent long-term gains. Over the last five years, the company's shares rose 263% and increased by 887% in the last decade.

Apple's growth is largely thanks to its dominance in multiple markets. As of the fourth quarter of 2022, Apple held the largest smartphone market share at 24.1%, a figure that has consistently grown from 13% in Q3 2019. Meanwhile, the company was responsible for a 49.7% market share in headphones in the U.S. in 2021 between its Apple and Beats brands.

Regarding digital services, Apple Music has the second-largest market share in music streaming, with 15% in Q2 2021, while Apple TV+ had a steadily growing 7% share in the streaming industry.

Apple is a diversified company with lucrative positions in multiple growing industries. Along with a history of consistent growth, its stock is an excellent long-term investment. 

2. Warner Bros. Discovery 

As with many consumer-reliant companies, Warner Bros. Discovery had a particularly tough 2022. Its over 60% stock slide during the year was triggered when the company took on $43 billion of debt from its merger with Discovery, with a long list of controversial restructuring moves that came after continuing to eat away at its stock price. However, Wall Street's faith in the company appears restored as its stock is up 59% in 2023.

After trimming content with countless shelved projects last year, Warner Bros. Discovery seems to be on the right path to fully take advantage of its valuable library of franchises that includes brands like Harry Potter, Game of Thrones, Lord of the Rings, and DC. The company slimmed down its content to put a larger focus on quality, which has already paid off with the success of its HBO Max series The Last of Us becoming the most-watched show in the platform's history.

Moreover, analysts from Wells Fargo and Wolfe Research upgraded Warner Bros. Discovery's stock on March 17, upping their price targets to $20 -- a 33% increase from its recent price. Wolfe's Peter Supino cited the company's strategy of paying executives based on free cash flow and debt paydowns. Supino expects Warner Bros. Discovery to "deliver high (>50%) of EBITDA (earnings before interest, taxes, depreciation, and amortization) to free cash flow as merger-driven charges subside."

With its stock still down 42% year over year, now is an excellent time to invest in Warner Bros. Discovery's stock for the long haul.

3. Amazon 

Amazon (AMZN -0.12%) shares plunged almost 50% last year as macroeconomic headwinds proved detrimental to its e-commerce business. The challenging year led its free cash flow to tumble to -$16.89 billion. The company responded by laying off 18,000 workers in November 2022, adding 9,000 to that list this March, canceling construction or closing down dozens of warehouses, and sunsetting projects such as its telehealth service Amazon Care.

However, Amazon's dominant positions in e-commerce and cloud computing will likely see it flourish again over the long term. According to Grand View Research, the e-commerce market was valued at $9.09 trillion in 2019 and is projected to expand at a compound annual growth rate (CAGR) of 14.7% through 2027. Meanwhile, Amazon's 37.8% market share in the industry will likely provide substantial gains once economic challenges subside.

Cloud computing is similarly expected to grow at a CAGR of 14.1% through 2030, with Amazon holding a leading 34% market share.

Amazon's stock is up about 19% year to date, with layoffs and new projects such as a venture into satellite internet to rival SpaceX's Starlink rallying investors. The company stumbled last year, but its long-term prospects remain positive, making its stock a compelling long-term buy.