Does Time Machine back up junk files and viruses along with everything else?
Time Machine backs up everything, including junk and malware, because it can't tell good files from bad. A clean system reinstall followed by a restore will often skip disguised system-file malware. The best protection is safe browsing habits, checking URLs before downloading, and keeping macOS updated so the built-in XProtect stays current.