To show hidden files in macOS Finder, open Terminal and paste this line:
defaults write com.apple.finder AppleShowAllFiles YES
To hide hidden files in macOS Finder (default behavior):
defaults write com.apple.finder AppleShowAllFiles NO
You will have to logout and login again for the change to take effect.
Update: much better solution from reader Don H:
I don’t know how far back MacOS supports this key combination, but in Mojave typing command-shift-. (period) toggles the visibility of hidden files instantly. Give it a try.
Sometimes cleanup jobs make showing hidden files useful (easy to find/delete), and sometimes seeing them is a nuisance. It’s OK to show and hide whenever needed. The Finder should just build this into the View menu, alas.