A capacitor stores charge and opposes changes in voltage. That second half is the useful part: put a capacitor across a supply rail and it fights every dip and spike, which is why one sits next to the power pin of nearly every chip ever placed.
Decoupling, the everywhere-capacitor
When a digital chip switches, it demands a gulp of current far faster than the supply can deliver through the inductance of the wiring. A 100 nanofarad ceramic right at the pin acts as a local reservoir for those first nanoseconds. This is the single most common capacitor job, and boards fail bring-up over a missing one more often than over any exotic mistake.
Choosing a type
Ceramics are small, cheap, and fast: the default for decoupling and small-value work. Electrolytics store far more per unit of cost and size but are polarized: reverse one and it fails, sometimes theatrically. The rule of thumb for a beginner bench: ceramics for nanofarads, electrolytics for microfarads and up, and always check the voltage rating has comfortable margin over the rail it sits on.
A charged capacitor also holds its charge after power-off. Big electrolytics in mains supplies can bite hours later, which is a good habit-forming reason to treat any large capacitor as live until measured.