There are different types of hacking like malware, phishing, email spoofing, and text message spoofing. Malware is mostly done by the coding language python and hackers use either files or links to trick you into downloading malware silently and harming your computer or more.
Which comes under phishing as phishing is when a hacker tricks you into clicking a link to give you malware or make you download a file. Then email spoofing is when you get fake scam emails which are for example asking you to click a link or input some type of detail which is often sensitive.
Text message spoofing is similar and sometimes is called smishing, in text message spoofing it sends scam texts like for example, asking for your bank information or sending you fake info saying your order has been suspended and you need to verify your credentials. This is a way hackers get your credentials and harm either your computer or your identity, as well as steal from your bank, etc.
There are also minor hackers, which do not cause any major harm, and for example theres been a famous scam where on an app like discord, you would get a message asking if you want to play roblox with that person, if you happen to say yes they will send you a link to their fake roblox profile, which is actually made with python and once you get on that link you will be logged out, asked to put your credentials in to log back in. Once you put your credentials in, you will not get logged in and instead the hacker gets your credentials on roblox.
First of all to prevent hacking the number one rule on the web is to not trust anyone. You must never browse and click random links sent to you or download any random files, never use third party sites or illegal sites like sites with free movies, as they consist of malware and viruses which harm your computer and get your credentials.