A capacitor's main function is to store electrostatic energy in an electric field and then supply that energy to the circuit whenever available.
They only allow alternating current (A.C.) to flow through them, preventing the circuit from being destroyed, while restricting direct current (DC) (D.C.).
When connected to a charging circuit, it retains electrical energy; however, when disconnected from the charging circuit, it loses energy and can thus be used as a temporary battery.
The fundamental purpose of a capacitor is to store energy.
Capacitors are used in a wide range of sectors and have become an essential part of daily life due to their diverse applications.