I have never own a Galaxy S4. But I had plenty of Samsung smart phones like Infuse, Galaxy S3, S5, S7 and S9. I had done my share of factory resets. They work pretty much the same except for 1 issue. Starting from one of the Android version, there was an anti theft feature. You cannot factory reset it unless you have the original Google account and password in order to complete the reset. If you don't have it and try the upgrade, you will turn the cell phone to a "door stopper". But I don't think it affects S4.
Before you reset, you need to backup the phone. There are many ways to do that and one of the easy one is Samsung Smart switch. Firmware upgrade would not be affected by factory reset. In other words, if the phone had been upgrade to Android "x", it will stay and the same Android "x" after reset. All the data and installed apps will be wipe clean. To do the actual reset, you just go to settings, general management, reset, factory data reset.