How does mic combined with loudspeaker work?
By using Acoustic Echo Cancellation. Since the signal that goes to the speaker is known you can subtract it out at the microphone, provided you know the exact transfer function from speaker to microphone. The determination of the transfer function is typically done through an adaptive filter. Similar techniques can be used to reduce reflections, reverberation and echoes from the room.

In addition, there are often multiple microphones using beam forming. The beams can be steered so that the pickup from the speaker is minimized (basically steering a null in the polar pattern to the speaker) and it can also be used to maximize pickup of the desired sound.

All of these things are really difficult, complicated and hard to get right. Cancellation and adaption often create artifacts that significantly reduce speech intelligibility. The quality of commercial implementation varies all over the place. In my name brand laptop, it's so bad that it's worse than useless and I simply turned it off. I have tried multiple USB speakerphones and also found a huge variability in quality. Finally I found one that actually works :-) but product recommendation are out of scope of this site. Let's just say that the one pictured is fairly decent.