A recession is coming this year -- that looks to be a near certainty. The country's real gross domestic product grew at an annual rate of only 1.1% for the first quarter, down from 2.6% in the previous period. And things are likely going to slow even more with interest rates still rising and companies continuing to scale back spending.

One company that may be resilient, however, is McDonald's (MCD -0.42%). The fast-food giant recently reported its latest earnings numbers, which suggested that demand remains strong even amid price increases. Here's why this may be the ultimate stock to be holding in your portfolio this year, even if you're worried about a recession.

Same-store sales were up an impressive 12.6% in Q1

An important metric for restaurant stocks is same-store sales. This tells investors how much growth was generated in restaurants that were operating a year ago. It's helpful because unlike the total revenue growth rate, it doesn't include new restaurant openings, so it can give a better indication of how the business is doing.

McDonald's same-store numbers were impressive, growing 12.6% for the first three months of 2023. And what's noteworthy is the improvement from the 11.8% same-store sales growth the fast-food company reported a year ago.

Even as the company has been raising prices and consumers have been dealing with tighter budgets, McDonald's business has remained resilient and growing. McDonald's is a global business, however,  and unfavorable foreign exchange rates have weighed on its results as revenue totaling $5.9 billion for the period was up only 4% year over year. But it was nonetheless a strong showing for the company as the growth rate was well above its long-run average.

MCD Revenue (Quarterly YoY Growth) Chart

MCD Revenue (Quarterly YoY Growth) data by YCharts

The stock has a solid track record

The company's business has proven a steady one to invest in, even as the markets have struggled. During the Great Recession of about 15 years ago, it performed much better than the S&P 500. Here's a look at its total returns, including its dividend:

MCD Total Return Level Chart

MCD Total Return Level data by YCharts

Not many stocks earned a positive return during the Great Recession. And while economic conditions are different now, McDonald's has proven itself able to weather the storm even amid inflation. The stock's 2% dividend yield isn't terribly high, but it can help bolster investor returns.

Is McDonald's stock too expensive?

The one negative about McDonald's is that its shares are trading at a hefty 31 times earnings, which may seem high given the S&P 500 average is 19. And McDonald's has averaged a lower multiple in recent years:

MCD PE Ratio Chart

MCD PE Ratio data by YCharts

But the company has been working on improving its bottom line, announcing earlier this year that it would be laying off hundreds of staff and reducing pay. This past quarter, it incurred a restructuring charge totaling $180 million, before taxes, in relation to its cost-cutting efforts. Earnings per share still jumped 66% in Q1 to $2.45, however.

Plus, with cost-cutting efforts in their early stages, greater cost savings could be coming for the business, which should bring down the earnings multiple in future quarters.

Should you buy McDonald's stock?

McDonald's is a good stock to own for the long haul given the company's ability to continue to find ways to draw consumers in and perform well under myriad economic situations. And even though its valuation may not look cheap right now, this can still make for an excellent investment to buy and hold because McDonald's financials should improve as it keeps growing and focuses on reducing its costs. Plus, its dividend can provide you with a solid stream of recurring cash flow for your portfolio.

Overall, McDonald's stock may end up being one of the best investments to be holding if a recession hits.