In the broadest terms, it is technically possible for a Nintendo Switch console to get a virus. It is a computer, and it is connected to the internet, and as with any other internet-connected device, a virus could get at it, at least in the most literal sense.
However, the notion of making a Switch-attacking virus would be generally unappealing for hackers for a handful of reasons. First and foremost, the Switch doesn’t have a standalone internet browser app. The easiest way to get a virus is to visit a compromised website, but that’s not an option. The only way to get software on a Switch that isn’t made by Nintendo is through game or app software.
This leads us to the second reason: eShop security. While there is no shortage of miscellaneous junk games on the Switch eShop, none of those games are outright malicious. This is because every game that tries to get listed on the eShop is vetted by Nintendo’s security team. Unless a hacker makes an extremely advanced virus, it’d be caught and blocked in a heartbeat. Even in such a circumstance, the hacker would need to spread the word about their infected app and convince people to download it, which would require quite a bit of effort in its own right.
So, in summation, while your Switch could get a virus, its ecosystem is so isolated that the pursuit just isn’t worth it.