Walmart on Thursday reported earnings that topped analysts' expectations and raised its forecast for the full year heading into the holiday season.

Earnings were fueled by robust e-commerce sales, as the company continues to gobble up online brands to compete with Amazon in categories like apparel and home goods, while also scaling its grocery business.

Comparable sales climbed for their 16th consecutive quarter, as existing Walmart shoppers flocked to its stores more frequently and added more to their baskets. The big-box retailer's revenue fell short of analysts' estimates, however, due to currency headwinds. It's taken a hit in recent quarters due to increased investments overseas.

Walmart shares ended the day down nearly 2 percent. With Thursday's losses, the stock is up more than 10 percent from a year ago, bringing Walmart's market cap to roughly $291.5 billion.

Here's what Walmart reported compared with what analysts were expecting, based on a survey by Refinitiv:

* Earnings per share: $1.08, adjusted, vs. $1.01 expected

* Revenue: $124.89 billion vs. $125.55 billion expected

* Same-store sales: up 3.4 percent in the U.S. vs. growth of 3.1 percent expected

"We have momentum in the business as we execute our plan and benefit from a favorable economic environment in the U.S.," CEO Doug McMillon said in a statement.

Walmart reported net income for the fiscal third quarter of $1.71 billion, or 58 cents a share, compared with $1.75 billion, or 58 cents per share, a year ago. Excluding one-time items, Walmart earned $1.08 per share, 7 cents ahead of analysts' expectations based on a survey by Refinitiv.

Revenue climbed 1.4 percent to $124.89 billion from $123.18 billion a year ago, falling short of expectations for $125.55 billion. Excluding impacts from currency, revenue was $126.1 billion.

Sales at stores in the U.S. open for at least 12 months were up 3.4 percent, better than growth of 3.1 percent expected by analysts. Walmart said traffic at stores was up 1.2 percent during the quarter, with the average shopper's ticket up 2.2 percent. CFO Brett Biggs told CNBC that grocery helped fuel those results, as Walmart now has a grocery pick-up option at roughly 2,100 stores across the U.S., and grocery delivery at about 600 locations.

Online sales were up 43 percent during the third quarter, and Biggs said the company is still on track to meet its goal of 40 percent e-commerce sales growth for the full year. A year ago, digital sales climbed 50 percent, as the company just started to lap its acquisition of Jet.com.

There's been some concern that as the U.S. economy cools off, however, Walmart's results won't be as strong. But some analysts still view the company as a beneficiary, "independent of how the macroenvironment is."

"We're probably about six months away from a slower consumer spending environment, as the boost from the tax reform starts to fade," UBS analyst Michael Lasser told CNBC. "And so there's a move away from some of the retailers that were disproportionately benefiting from that, to more safe-haven defensive-type retailers like Walmart."

Though there are uncertainties around rising interest rates and rising costs because of tariffs, Lasser said, "Walmart has a good plan" in place to work around them. That includes deploying robots and other technology in stores so that the company can save money and put resources toward more labor-intensive tasks, he said.

In a recorded message, Biggs expressed confidence in the retailer's plan, saying, "We feel good about our competitive position heading into the holiday season. The business remains strong, we're executing our strategy well..."

Part of that strategy this year is to be focused on expanding its merchandise assortment online. One way it's doing this is by acquiring digital brands, including most recently plus-size fashion retailer Eloquii and intimates company Bare Necessities. The head of Walmart's U.S. e-commerce business, Marc Lore, recently said Walmart could one day own more than 40 of these e-commerce retailers.

With this growth, Walmart is expected to overtake Apple as the third-largest e-commerce retailer by sales in 2018, falling only behind Amazon and eBay, according to a new report from eMarketer. Walmart is expected to take 4 percent of U.S. e-commerce sales, or roughly $20.9 billion, the market research firm said.

"We have an opportunity to improve the margin mix in this business, and we'll do this by expanding the tail of the [online] assortment through first-party items and marketplace," McMillon said Thursday.

Looking to the full year, Walmart now expects same-store sales in the U.S. to rise "at least" 3 percent, compared with a previous outlook of "about" 3 percent. It says adjusted earnings per share will fall within a range of $4.75 to $4.85, up from a prior range of $4.65 to $4.80.

In October, Steve Bratspies, chief merchandising officer for Walmart U.S., told reporters that its plans was "building up to what we think will be the best holiday yet."

Internationally, Walmart has been looking for ways to grow to outpace its rivals like Amazon and Alibaba, including in China, Canada and the U.K.

It recently paid $16 billion to acquire a majority stake in Indian e-commerce company Flipkart, as one example, to get a foothold in that fast-growing economy. The CEO of Flipkart, Binny Bansal, resigned earlier this week after an internal probe into "serious personal misconduct."

International sales fell 2.6 percent during the third quarter to $28.8 billion, partly due to the company selling a majority of its Brazilian business to private equity firm Advent International. Walmart said same-store sales were positive in 9 out of 10 markets where it operates overseas.