That’s a very interesting question. I did my best to make the answer as clear and concise as possible. If you think the answer is worth it, please upvote.
By definition, covalent compounds are compounds in which electrons can be shared between atoms to form a stable octet.
You may now be asking why these electrons are shared. There are elements such as Carbon, Silicon, and others that have a surprising number of electrons. The puzzling number can range from 3,4 to 5, and sometimes more. This makes it impossible for the element to lose electrons or gain electrons. The only option for that element is to share an electron with other elements in order to create a stable octet.
Many times, Elements that have many electrons such as 2,3,5,6,7 form covalent bonds to create a complete octet.
Hope you understand. Plz upvote.