Any element want to get stabilised. To get the stability an element needs to have completely filled electrons in the outermost shell. This is known as octet rule.
So, any element has if electrons less than the respective number, it either donates those electrons or accepts extra electrons to get the outer shell completely filled.
We hope that clarifies your query.