The covariance between two random variables which are each integrable and whose product is integrable is the expectation of their product less the product of their expectation.
Let $f$ and $g$ be two integrable random
variables with $fg$ integrable.
Denote the covariance of $f$ with $g$ by
$\cov(f, g)$.
We defined it:
\[
\cov(f, g) = \E (fg) - \E (f)\E (g).
\]
\[ \cov(f, f) = \E (ff) - \E (f)\E (f) = \E (f^2) - (\E (f))^2 = \var(f). \]
\[ \begin{aligned} \textstyle \var \sum_{i = 1}^{n} f_i &= \cov(\sum_{i = 1}^{n} f_i, \sum_{i = 1}^{n}f_i) \\ &= \sum_{i = 1}^{n} \sum_{j = 1}^{n} \cov(f_i, f_j) \end{aligned} \]