We have measured inelastic-electron-scattering spectra of several hexagonal-boron-nitride samples with momentum transfer both in and out of the a-b plane and obtained the dielectric and optical constants from 0 to 60 eV. The low-q energy-loss spectrum with momentum in the plane is dominated by the \ensuremath{\pi}-electron plasmon at 8.5 eV and the total (\ensuremath{\sigma}+\ensuremath{\pi}) plasmon at 26.4 eV. The \ensuremath{\pi} plasmon arises from two strong interband transitions at 6.1 and 6.95 eV, and a continuum threshold at 7.6 eV. The plasmons are well described as collective oscillations of bound electrons. We have inferred a band gap of 5.9 eV by observing the intrinsic absorption threshold in a series of samples of varying purity. The dispersion in the plasmons and the second interband transition is quadratic for 0lql1.0 A${\r{}}^{\mathrm{\ensuremath{-}}1}$, while the first interband transition disperses upward in energy up to 0.6 A${\r{}}^{\mathrm{\ensuremath{-}}1}$, above which its energy remains almost constant. The dispersion of the \ensuremath{\pi} plasmon is equal to that of the second interband transition, and its width remains constant up to a critical momentum, indicating that its width is dominated by decay into single-particle transitions. The energy-loss function with q along c shows three collective oscillations at 7.7, 11.7, and 23 eV. The interband spectrum is similar to that with q in the plane, except that an additional transition appears at 9.9 eV and the oscillator strength is shifted to higher energies. The similarity in the spectra for q in and out of the plane indicates nearly degenerate occupied \ensuremath{\sigma} and \ensuremath{\pi} states near ${E}_{F}$, which is inconsistent with existing band-structure calculations.