Amazon (AMZN -1.35%) and Apple (AAPL -2.19%) are two of the world's leading tech companies, with market caps at $961 billion and $2.35 trillion, respectively. These companies have competed in consumer tech and, more recently, streaming. 

A sell-off in 2022 led Amazon and Apple's stocks to tumble, with both companies' shares still down year over year. As a result, now is an excellent time to consider adding one of these tech giants to your portfolio. Amazon's leading market share in e-commerce and cloud computing will likely see it flourish over the long term. Meanwhile, Apple's dominating position in consumer tech and digital services has offered reliable growth over the long term.

So, is Amazon or Apple's stock the better buy? Let's assess.

Amazon: Waiting out economic headwinds

In fiscal 2022, Amazon's e-commerce business was hit particularly hard, with operating losses in its North American and international segments totaling $10.6 billion. Rising inflation triggered reductions in consumer spending and effectively made the segments responsible for 84% of Amazon's revenue unprofitable.

However, the economically challenging environment will not last forever, and the company's leading 37.8% e-commerce market share in the U.S. will likely pay off in the long term. According to Statista, e-commerce sales earned $5.2 trillion worldwide in 2021, with that figure expected to reach $8.1 trillion by 2026, rising 53.8%.

Meanwhile, AP News reported on Feb. 14 that inflation had eased for the seventh month in a row in January, hitting 6.4% after a high of 9.1% in June 2022.

It might not be this year, but Amazon's e-commerce segment will more than likely return to profitability. In the meantime, the company's cloud computing service, Amazon Web Services (AWS), has done a nice job at keeping profits up. The cloud platform earned 100% of the company's $12.25 billion in total operating income in 2022. AWS also showed promise after a revenue rise of 28.8% year over year to $80.1 billion. 

It will take time for Amazon to return to its pre-2022 form. However, its long-term outlook makes its stock an attractive buy after a sell-off. 

Apple: Shifts in its iPhone strategy

Toward the end of 2022, Apple concerned investors after a spike in COVID-19 cases in China caused production strains at the factory producing about 70% of all iPhones. The issues made critics question Apple's reliance on China for manufacturing, as iPhones earned 52% of the company's total revenue in fiscal 2022.

However, Apple is taking promising steps to boost its smartphone revenue over the long term and safeguard its cash cow. The company is gradually increasing the number of its products made in countries like India and Taiwan. Meanwhile, on March 3, Bloomberg reported that Foxconn Technology Group, also known as Hon Hai Precision Industry and the owner of the factories producing most iPhones, will invest $700 million to ramp up Apple product manufacturing in India.

In addition to moving out of China, Apple is reportedly in the process of improving the profit margins for its iPhones by using more in-house components. Bloomberg revealed in January that the company plans to move away from costly partnerships with Samsung and LG by developing custom displays for its smartphones, taking a similar approach with telecom chips and its reliance on companies like Broadcom and Qualcomm.

Amazon and Apple have positive outlooks over the long term. However, Amazon stock's decline of 49.6% throughout 2022 compared to Apple's stock tumble of 26.8% has put the iPhone company in better standing. Amazon's business suffered far worse amid economic challenges, with its free cash flow at a negative $16.9 billion, while Apple's is $97.5 billion.

Moreover, Amazon's forward price-to-earnings ratio of 77.1 against Apple's 25.6 suggests the MacBook manufacturer's shares offer far more value. As a result, Apple's stock is currently the better buy, with Amazon still a great option to hold over many years.