  The Jiangmen Underground Neutrino Observatory~(JUNO) features a 20~kt
multi-purpose underground liquid scintillator sphere as its main detector. Some
of JUNO's features make it an excellent experiment for $^8$B solar neutrino
measurements, such as its low-energy threshold, its high energy resolution
compared to water Cherenkov detectors, and its much large target mass compared
to previous liquid scintillator detectors. In this paper we present a
comprehensive assessment of JUNO's potential for detecting $^8$B solar
neutrinos via the neutrino-electron elastic scattering process. A reduced 2~MeV
threshold on the recoil electron energy is found to be achievable assuming the
intrinsic radioactive background $^{238}$U and $^{232}$Th in the liquid
scintillator can be controlled to 10$^{-17}$~g/g. With ten years of data
taking, about 60,000 signal and 30,000 background events are expected. This
large sample will enable an examination of the distortion of the recoil
electron spectrum that is dominated by the neutrino flavor transformation in
the dense solar matter, which will shed new light on the tension between the
measured electron spectra and the predictions of the standard three-flavor
neutrino oscillation framework. If $\Delta
m^{2}_{21}=4.8\times10^{-5}~(7.5\times10^{-5})$~eV$^{2}$, JUNO can provide
evidence of neutrino oscillation in the Earth at the about
3$\sigma$~(2$\sigma$) level by measuring the non-zero signal rate variation
with respect to the solar zenith angle. Moveover, JUNO can simultaneously
measure $\Delta m^2_{21}$ using $^8$B solar neutrinos to a precision of 20\% or
better depending on the central value and to sub-percent precision using
reactor antineutrinos. A comparison of these two measurements from the same
detector will help elucidate the current tension between the value of $\Delta
m^2_{21}$ reported by solar neutrino experiments and the KamLAND experiment.
