How know if user is visitor or logged member? How can I determine programatically whether the current user is anonymous or authenticated?
For the sake of more robust and descriptive code, you can make use of the handy User::isAnonymous() method, e.g.

if (\Drupal::currentUser()-&gt;isAnonymous()) {
  // Anonymous user...
}