Diagram of a molecule of salt
When atoms get close together, sometimes they form ionic bonds that stick them together into molecules. These ionic bonds are weaker than covalent bonds, but they do still hold the molecules together.
Some kinds of atoms, like sodium, have only one electron in their outside ring, which is an unstable situation. Sodium's so unstable that if you add water to it it catches on fire! When those unstable atoms come near another unstable atom, they trade electrons until they find a more stable arrangement. Usually it's a metal atom joining up with a non-metal atom. For instance, when sodium atoms come near chlorine atoms, the chlorine atoms are also very unstable, because chlorine is missing an electron to fill up its outer ring. So when they get together, the sodium atom's extra electron jumps over to the chlorine atom. Then the chlorine atom is stable, and so is the sodium atom.
But the new stable atoms also have electrical charge, which they didn't before. The old atoms had the same number of protons and electrons: sodium had eleven protons and eleven electrons, and chlorine had 17 protons and 17 electrons. The positive charge of the protons balanced the negative charge of the electrons. But after the reaction, the sodium atom has one more proton than electron, so it has a weak positive charge. And the chlorine atom has one more electron than proton, so it has a weak negative charge. Just the way a negatively charged magnet pulls toward a positively charged magnet, a negatively charged atom (called a negative ion or anion) pulls toward a positively charged atom (called a positive ion or cation). This pull holds the sodium atom near the chlorine atom, making a molecule of salt - one of the most stable molecules on Earth.
Most of the solid things in the universe - like rocks - use ionic bonds to hold themselves together. That's because those same electric forces affect other nearby molecules of salt as well. Like magnets, any two positively charged chlorine ions will push away from each other, and so do two negatively charged sodium ions. At the same time, the chlorine ions pull on any nearby sodium ions, and the sodium ions pull on any nearby chlorine ions. So they end up arranged into a stiff crystal framework. You need higher temperatures to melt or boil rocks and other things with ionic bonds than you do with covalent bonds.
To find out more about molecules, check out these books from Amazon.com or from your library: