How know if user is visitor or logged member?
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...
}