Expand around the expectation :
Thus variance as the minimum mean squared error of a constant gives
The finite second moment also guarantees the finite first absolute moment needed below.
For a probability density function , splitting at gives
Let be the cumulative distribution function. Since a density gives no mass at a singleton, differentiating under this integral yields . This derivative is nondecreasing, so is convex and
This is the median minimizes expected absolute loss property. The minimizer need not be unique: a gap in the density can give an interval of medians, all with the same loss.
For every ,
After squaring and taking expectations, the cross term vanishes because . Therefore
The second term is nonnegative and vanishes exactly at , so the variance as the minimum mean squared error of a constant identity is