The world's most valuable company, and first to be valued at $4trn (£2.9trn), beat market expectations in keenly anticipated financial results.