There is a couple of ways to think about how gears work. I'll try to describe the practical use.
Gears take your input - pedaling the crank - and translate that into some level of mechanical advantage in propelling the rear wheel. The easier the pedaling gear, the lower the mechanical advantage, and the slower the bike goes. The higher the gear, the faster the bike goes, but the effort to pedal is higher.
The lowest gear (easiest to pedal, slowest) on a non-hub geared bike is the smallest chain ring (front) and the largest rear cog. The highest gear (hardest to pedal, fastest) is the largest ring on the front and smallest cog in the rear. The goal is to basically find the best combination for the pedaling effort and revolutions (cadence) you want to exert. If pedaling is too hard, shift the rear to a larger cog (down a gear), If you are pedaling with no resistance, then shift the cog to a smaller cog (up a gear).
If that isn't all confusing enough, if you have more than one chain ring in the front, you likely have a lot of overlap in the gearing. In other words, the small chain ring on the smallest cog will be roughly equivalent to some combination on the larger chainring with a larger cog. This is because of something called "cross-chaining" which happens when you try and run small chain ring and small cog or large chainring and large cog. The chain will often rub the front derailleur because it is at too much of an angle connecting the selected gears. When this happens, switch to the other chain ring and find the matching cog to stop the rubbing. Many e-bikes only have a single chain ring, so cross chaining is not an issue.
I know this sounds complicated, but it is easier when you just experiment. My suggestion is that you find a pedal effort and speed you are comfortable with and then find the gear that makes that possible. As the road moves up or down, adjust for that.
As for mid-drive e-bikes, the motor is using the same drivetrain as your legs, so the gear is important to make sure the motor is running efficiently. If you pedal without a motor in a really high gear, you will likely tire quickly because your legs are expending a ton of energy. The motor works the same way. Current draw goes up, the motor works harder, and is inefficient. Think of trying to start your car in 4th gear. It would chug and buck and fight you. Bike gearing is the same.
I don't know if any of this helped, but hopefully it helped a little.