Walmart (WMT 1.32%) just delivered a strong fourth-quarter earnings report to kick off the retail earnings season, beating estimates on the top and bottom lines.

The retail giant flexed its muscles in its core markets, posting mid-teens comparable sales growth in grocery at Walmart U.S. That drove comparable sales up 8.3% and operating income higher in its biggest segment, despite inflationary pressure.

While Walmart is best known as a retail behemoth with the "everyday low prices" promise, the company has reinvented itself in recent years, becoming an omnichannel by adding grocery pickup stations, launching the new Walmart+ membership program, and building out an advertising business.

In addition to the strong performance of the core business, also notable is that Walmart is outperforming top competitors like Amazon (NASDAQ: AMZN) and Costco Wholesale (NASDAQ: COST) head-to-head.

Walmart's revenge

Walmart, Amazon, and Costco are the three biggest retailers in the U.S., and while Walmart is the biggest of the three by revenue, it has lagged behind the other two in stock performance over the long term.

WMT Chart

WMT data by YCharts

While Amazon has long been viewed as the most disruptive force in retail and Costco is admired for its well-run membership-based warehouses, Walmart is at times seen as something of a relic in the industry -- a retail powerhouse of yesteryear that has lost its competitive advantage to more nimble e-commerce competitors.

However, that is no longer the case. Walmart continues to make strides in its new categories while maintaining its core strengths, and it's gaining market share on both Amazon and Costco.

In e-commerce, for example, Walmart posted 17% growth in its U.S. segment in the fourth quarter, driven by store-fulfilled pickup and delivery as well as advertising, and 21% e-commerce growth in Sam's Club thanks to the performance of curbside pickup and ship-to-home. The company said that e-commerce generated more than $80 billion in sales for the full year, or 13% of total revenue, making it one of the biggest e-commerce businesses in the world.

By comparison, Amazon's revenue grew just 9% in the fourth quarter, or 12% in constant currency. Its North America segment posted 14% constant currency revenue growth, while its international segment grew constant currency revenue by just 5% in the quarter.

Amazon's online stores segment, or first-party e-commerce, saw constant-currency revenue grow just 2% in the quarter to $64.5 billion, a good indication that Walmart gained market share on the top e-commerce company.

Meanwhile, Sam's Club is also outperforming Costco. Walmart's own membership-based warehouse club reported comparable sales growth of 12.2% in the quarter excluding fuel, driving overall revenue up 11.3% to $21.4 billion. Membership income also rose 7.1% with the help of a fee hike in October.

Costco has a different reporting calendar, but its comparable sales growth was just 7.1% excluding fuel through the 22 weeks up to the end of January, showing it also lost market share to Walmart.

Room for growth

Walmart's strong performance in e-commerce and Sam's Club is a reminder that even though the company brought in $611 billion in revenue last year, it still has opportunities for growth.

E-commerce, in particular, remains a ripe market, and part of the reason why Walmart is outgrowing Amazon is that Walmart can grow in areas that Amazon hasn't really touched like grocery, online pickup, and store-based delivery.

Recent performance in Sam's Club shows that Walmart has the potential to build it into a business that's as valuable as Costco.

Walmart expects a challenging and uncertain year ahead, and the company said its guidance was conservative, calling for adjusted earnings per share of $5.90 to $6.05, or $6.04 to $6.19, excluding a last in, first out (LIFO) adjustment.

That guidance was worse than the consensus of $6.50 and below its 2022 results of $6.29.

Like most retailers, Walmart is facing a challenging year as inflation and recessionary fears are weighing on consumers, but the company's performance in e-commerce, Sam's Club, and other new businesses show it's well positioned for the long term. As it captures market share and builds out new profit streams, the stock looks like a smart buy today.