its pritty useful infact, in effect a hosts file is very much like a phonebook, you want to talk to a website/person you look them up in the Hosts file/phonebook by name.
now your local hosts file, just like your phone book is the very first thing you check, and if you cant find the name there,or dont have one, you use your ISP given DNS server/ring Directory Enquirys.
now instead of always using the ISPs DNS or the DE to find the right No, you make your own local Hosts file/DE that will always be the very first thing your browser uses to lookup and find the No.
for the bad sites, whatever that might be, you dont use the real No. in there, you replace it with a local Ip adress false No instead.
so any time
www.badWebsite.com is referenced by any webpage, instead of going to the real webside IP address, it now gets sent to the local IP 127.0.0.1 ,and so cant access any of the content on that bad sites pages ,you are not connecting to it, so it cant send you anything.
as an example of forcing a URL look up to direct to somewere else.
if for instance you have a hosts file with this in it
87.106.129.133
www.cableforum.co.uk
that would work and send your browser to CF, as its the right current IP No.
However if you instead had this IP No. in your hosts file.
91.186.24.166
www.cableforum.co.uk
no matter how many times you tryed it, you would not get to CF but rather
www.CableHell.co.uk instead.
the names are the same But the browser now thinks 91.186.24.166 IS CableForum not CH.
just as
127.0.0.1
www.cableforum.co.uk
wouldnt go past the local machine, never mind make it on to your LAN or the wider WAN/ISP
direct IP No.s always override the website name as found in any DNS list, be it the Hosts file or an ISP/3rd party DNS server.