What happened

Shares of Apple (AAPL 5.98%) are ending the week on a high note, gaining as much as 5.1%. As of 10:53 a.m. ET, the stock was still up 4.8%.

The broader market was solidly in rally mode, which no doubt contributed to tech giant's rise. However, the biggest news was Apple's quarterly results, which were far better than many feared.

So what

In its fiscal second quarter (ended April 1), Apple generated revenue of $94.8 billion, down 3% year over year, resulting in earnings per share (EPS) of $1.52, level with the year-ago period. Apple shareholders breathed a sigh of relief, having feared the combination of high inflation, rising interest rates, and continued economic uncertainty would have weighed more heavily on sales. 

To put the results in the context of Wall Street's expectations, analysts' consensus estimates were calling for revenue of $92.9 billion and EPS of $1.43, so the tech titan cleared both hurdles with ease.  

Apple fans had other reasons to celebrate. Services was the highlight, with revenue rising to $20.9 billion -- an all-time record for the segment. iPhone sales also jumped, as revenue set a record of $51.3 billion, the highest ever for the fiscal second quarter. 

On the heels of its strong performance, Apple said it was raising its dividend to $0.24, an increase of 4%, payable on May 18 to shareholders of record as of the market close on May 15. This marks the 11th consecutive annual increase.

The company also announced an additional $90 billion share repurchase plan, which will entitle remaining shareholders to an incrementally larger slice of its profits.

Now what

Naysayers have been waiting for the other shoe to drop, but Apple continues to largely defy the downturn. CEO Tim Cook suggested that consumer demand was holding up well and was particularly strong in emerging markets. 

Given the current economic headwinds, Apple was reticent to provide many specifics for the upcoming quarter, but analysts' consensus estimates are calling for revenue of $84.5 billion, an increase of about 2%, and EPS of $1.20, essentially flat.

The consistent strength of Apple's business in the face of headwinds is a remarkable achievement. Its strong performance, industry-leading position, and shareholder-friendly practices make the stock a buy.