One way to avoid this in the future is to not revisit the website where it just happened. Apparently, either their site has been compromised by someone who inserted scareware, or perhaps it's their own "feature" which supplements their income, i.e. the site itself is lying about its content.
Another way malware, scareware, and viruses can spread is through ad banners.
Ad banners can be an attack pathway, even on mainstream websites, because ad space is commonly sold and filled by companies that have no affiliation with a website or the website's primary ad supplier. In other words, the ad space on your favorite website may be managed by Google's ad network. And in turn, Google may fill the space with ads Google sold or with ads sold by other ad networks, many of which are unscrupulous or uncaring about security.
----------
ETA: I have a utility,
RansomWhere?, that was developed by a respected authority on Mac security, Patrick Wardle. It is not for everybody; if you are not prepared to interpret and allow/disallow the warnings it puts up, you probably are better off without it. But I like it and have been using it without any negative experiences for a long time.
Also, anybody who is relying solely on the built-in macOS security tools (XProtect, XProtectRemediator, Gatekeeper, and MRT) should not use any version of macOS prior to Catalina. Here's why:
and
If you’re still running macOS Mojave or earlier, now is the time to take action to ensure your Mac maintains protection against malware.
eclecticlight.co
Note that Apple is very opaque about which threats are stopped by the macOS tools. It is difficult to confirm or deny the extent to which macOS stops ransomware.
----------
ETA 2: Good advice from Howard Oakley.
"If this article does nothing else, please take the opportunity to check that your Macs are fully up to date and that their protection is functioning properly. Although that’s far from simple in macOS, you’ll find third-party tools like my own SilentKnight, silnite and XProCheck a good start. And they’re completely free to use, and have no annoying habits."
John clicked on the wrong email, and suspected something malicious. From there on, nothing went right. He couldn’t even check macOS protection. A salutary tale.
eclecticlight.co