Basically, there are two ways your webcam can get hacked. The first way is too easy, and happens when you don't change the default username and password on your webcam. As Lifehacker explains, some webcams can be accessed remotely and have a default username and password that allows you to do so. The problem is, this default username and password is the same one issued with every device, which means it's really easy to get ahold of. Now, that problem goes away as soon as you change your password, but there's another way people can hack into a webcam that is far more dangerous.
The second way involves a malware called remote access trojan (RAT), which takes control of the device, letting the hacker watch you from that compromised webcam. What should you do to prevent this? Well, as Naked Security points out, you should avoid clicking on suspicious links and maybe get some security software, but one easy way to ensure that the hacker can't see you is to cover up your webcam with a piece of tape. Yep, just like Zuckerberg.