Warning: Consult your Immigration Attorney before traveling while your H-1B Visa application is pending with USCIS.
In some cases, you could travel and it may be a good thing. For instance, your have STEM OPT for 18 more months and you like to save more money because STEM OPT workers are not required to pay FICA taxes. And it could be risky as well.
H-1B Application for someone located within the US could be applied with Change of Status (COS) application or without Change of Status request.
Applicants applying for H1B from outside the USA, always apply without COS.
When the applicants depart the US while the COS is pending, they are essentially abandoning the COS application. While H1B petition could be approved, COS would not be approved.
Example: If student on OPT applies for H1B, gets selected in the lottery, then travels outside the US while the application is pending, then the student can enter the US on F-1 (if the stamp is still valid). If the H-1b start date is October 1st, their status will not be switched to H-1B automatically. One has to travel outside the country, attend H1B Visa interview at U.S. Visa post and enter the US with new I-94 on H-1B Status.