Format a phone number function
I don't know of any coding standards or other reasons why you should have to move it higher. Generally it's just personal preference and whichever is more readable.

As for the fact that you'd need to create a variable unnecessarily in some cases, creating a variable like this uses very little memory so it shouldn't be an issue unless the function is being looped over thousands of times. 

You could also consider another option, which is to use a ternary rather than mutating a variable:
let prefix = phoneNumberString.startsWith('49') ? '49' : ''