NEW YORK — Facebook is attracting advertising dollars to where its users are — on mobile devices.

The world’s largest online social network surpassed expectations on all fronts in the second quarter. It grew not just profit and revenue, but also its already-massive user base and mobile advertising, as well as usage of its “family” of non-Facebook apps like Instagram, Messenger and WhatsApp. Even so, its stock price slid after the quarterly results came out, as expenses soared 82 percent and cut into earnings.

Facebook said Wednesday that it had 1.31 billion people visiting from a mobile device at least once a month, on average, during the quarter. That was up 23 percent from a year earlier.

Facebook had 1.49 billion monthly users overall, up 13 percent. It also had 968 million daily active users overall and 844 million on mobile devices. “Once again Facebook has proven its ability to attract and retain users,” said Forrester Research analyst Nate Elliott. “It’s particularly impressive that users are more engaged than ever before — that the percentage of monthly users who visit every day continues to grow.”

That’s in contrast to Twitter, which continues to worry investors with stalling user growth and on Wednesday saw its stock price drop to its lowest level in more than a year.