What fastboot erase actually does? I've seem some suggestions on the internet that we can do a factory reset on the Motorola Moto G (2nd gen) by using the following commands:

fastboot erase modemst1 
fastboot erase modemst2 
fastboot erase cache
fastboot erase userdata


Or another variant with just

fastboot erase cache
fastboot erase userdata


Now, the fastboot CLI provides the following description for "erase":


  Erase a flash partition.


In that case, I'm worried that these commands just erase the partition, instead of reseting to factory state.

What I mean is: what this erase command actually do? It erases the partition leaving nothing there, or it restores it to the factory state?

These commands really do a factory reset through fastboot?
This thread on XDA has a post 



  ....what is the aim of the "fastboot erase modemst" command?


Answer


  modemst1 and modemst2 are storage partitions for Radio Firmware .... - and it's obviously a recommended practice to wipe these partitions when flashing a newer Radio Firmware



This XDA thread is all about fastboot commands


fastboot erase system

fastboot erase data

fastboot erase cache

Are explained as 


  fastboot allows for about the cleanest of wipes by the way. And each partition can be done separately too.


Elsewhere in same thread


  ... with a lot of new phones userdata = /data + /sdcard (/data/media), so all data, any personally saved files, and system are flushed out permanently with fastboot's erasure. Note that TWRP factory reset would leave /data/media intact


So, putting your list of commands in question, a device is being wiped cleanly of all the partitions mentioned including all data, and thus getting ready to flash a new ROM on the cleanest manner as against dirty flash which has remnants of earlier ROM  affecting performance