Stocks "are bouncing back ... in what is proving to be a year of amazing of resilience for the asset class and silencing the bears," said Nick Raich, CEO of The Earnings Scout. "Market bears had one eye open yesterday, but are slipping back into hibernation."
The S&P 500 gained 0.8 percent to finish at 2,585.64, with consumer staples and information technology among the best-performing sectors. Wal-Mart was one of the best-performing stocks in the index after its strong earnings, which were boosted by a surge in grocery and online sales.
"Overall the [fiscal third-quarter] result suggests investments continue to favorably impact comp growth and shows Walmart is effectively competing in a tough retail environment," Mark Astrachan, an analyst at Stifel, said in a note.
Before Thursday's rebound, the major stock indexes came had fallen in their previous two sessions, as concerns about tax reform and a pullback in commodities worried investors.
The House passed a bill Thursday aimed at overhauling the U.S. tax code. If the bill becomes law, it would immediately slash the corporate tax rate to 20 percent from 35 percent. However, the House bill contains key differences from that of the Senate, especially on how to treat state and local tax deductions. Expectations of tax reform have helped stocks reach all-time highs recently.
Global stocks also rebounded on Thursday. In Europe, the Stoxx 600 gained 0.8 percent. Asian markets also closed mostly higher, with the Japanese Nikkei 225 advancing 1.5 percent and the South Korean Kospi index gaining 0.7 percent.
"You would expect a small rebound after several days of declines," said Komal Sri-Kumar, president of Sri-Kumar Global Strategies. But he also noted that investors should remain alert as uncertainty surrounding global central banks and Brexit, among others, remained. "I would not get too excited about today's rally."