It's not a simple question. There are numerous mode options, and different camera brands do things differently. Not to mention bounce and diffuser techniques which are integral to using flash to full advantage - if you don't do that, you might just as well use the pop-up (if you had one

).
Av is usually favourite of the auto modes, or manual, but you can use any camera mode, and with the flash in either auto (Canon E-TTL) or manual. Lots of permutations.
With Canon, the default on Av is to balance the shutter speed with the background ambient light, and the flash fills the foreground. But you can override that in custom functions. In P, the camera will allow the shutter speed to drop below the max x-sync down to 1/60sec, and then it stops, preferring to let the background go dark rather than risk background bluring.
If you want to learn how to do things properly, and really you should because it can absolutely transform your pictures, get the Speedliter's Handbook by Syl Arena, £18 Amazon. V good book
