Conservative forces and potential energy

For a conservative force the work is path independent, so it can be stored as potential energy $U$ with $F = -\frac{dU}{dx}$, like $mgy$ for gravity and $\frac{1}{2}kx^2$ for a spring.

From Physics 1.