There's no question about it. 2023 has been a disappointing year for Target (TGT 0.18%).

Weakness in discretionary goods, pressure from inflation and interest rates, and challenges related to product theft have all weighed on the company's performance this year. Comparable sales continue to slide, and the stock trades down 12% year to date, compared to 17% growth for the S&P 500.

On the plus side, Target delivered a surprising win for investors on Wednesday: The stock jumped 18% after it easily beat earnings estimates in its third-quarter report.

Top-line sales continued to decline, with comparable sales down 4.9% in the quarter due to continued challenges in discretionary categories. Overall revenue was down 4.2% year over year to $25.4 billion. However, the company lapped a period in which it struggled with bloated inventory levels and excess markdowns, and better cost controls helped drive profits higher.

Inventory in the quarter fell 14% year over year and was down 19% in discretionary categories, helping to reel in markdowns; margins expanded across the board. As a result, earnings per share jumped 36% from $1.54 to $2.10, easily beating estimates of $1.48.

Investors responded positively to the strong earnings beat, but Target's guidance showed that headwinds would persist into the fourth quarter. The company forecasted a comparable-sales decline in the mid-single digits. It also guided for adjusted earnings per share of $1.90 to $2.60, an improvement from $1.89 in Q4 2022, but that represented relatively modest growth from the third quarter -- the fourth quarter is the seasonally strongest period for Target.

Overall, the results showed that many trends from earlier in the year have persisted. The difference is that management got better at managing costs; the bottom line easily beat its own guidance.

The chart below shows how the quarter broke down for the retailer:

A chart showing Target's performance in the third quarter of 2023.

One surprising bright spot for Target

Outside of cost savings, there was one area where Target showed surprising strength. Same-day fulfillment services continued to outperform, with sales rising 8% year over year. Drive Up, Target's curbside pickup program, was the biggest star, featuring 12% growth. It had a key new driver: Target recently gave customers the ability to order from in-store Starbucks (SBUX 0.47%) locations when they come to pick up their Target orders. The company rolled out the service nationwide and said that it's now getting nearly 100,000 Starbucks orders weekly through Drive Up.

Nearly all Target stores now have a Starbucks inside. That partnership and the company's ability to include Starbucks orders with Drive Up are reminders of Target's unique strengths -- no other retailer is able to offer that. The company has also forged partnerships with brands like Ulta Beauty and Walt Disney that help distinguish it further, even as it continues to face challenges in discretionary spending.

Is the worst over for Target?

Target's surge on Wednesday seems to signal that the worst may finally be over for the stock. Expectations had fallen low enough that the recent results were able to drive an 18% gain in the stock, even as sales continued to slide.

The good news is that shares continue to look undervalued, trading at a forward P/E of roughly 15. But Target offered little indication on the earnings call of when it expected sales to return to growth.

That's because the underlying trends there are outside of the company's control. Demand for discretionary goods continues to be weak across the retail sector. Americans have shifted their discretionary spending from goods to services like travel and restaurants that were off-limits for much of the pandemic. Meanwhile, inflation and interest rates have had an impact on consumer confidence, and there are signs that the economy could continue to weaken into 2024; for example, monthly retail sales in the U.S. declined 0.1% in October.

At this point, there's too much uncertainty in the economy and the retail sector to say that Target is on the rebound, but long-term investors who buy the stock at this point are likely to be rewarded.

The competitive advantages Target showed off during the pandemic are still intact. The stock appears to be oversold, as evidenced by the post-earnings rally. And it currently offers both an affordable valuation and a dividend yield of 3.4%. Patient investors here should eventually be rewarded.