Lanthanum hydride LaH$_{10}$ with a sodalitelike clathrate structure was experimentally realized to exhibit a room-temperature superconductivity under megabar pressures. Based on first-principles calculations, we reveal that the metal framework of La atoms has the excess electrons at interstitial regions. Such anionic electrons are easily captured to form a stable clathrate structure of H cages. We thus propose that the charge transfer from La to H atoms is mostly driven by the electride property of the La framework. Further, the interaction between La atoms and H cages induces a delocalization of La-5$p$ semicore states to hybridize with H-1$s$ state. Consequently, the bonding nature between La atoms and H cages is characterized as a mixture of ionic and covalent. Our findings demonstrate that anionic and semicore electrons play important roles in stabilizing clathrate H cages in LaH$_{10}$, which can be broadly applicable to other high-pressure rare-earth hydrides with clathrate structures.