How to Check if user is Authenticated or not in drupal 8

I recently searching for this topic.

Problem: Want to show some content to anonymous user and different content to logged in user.

So here is the code:

$check_user = \Drupal::currentUser()->isAuthenticated();

Condition:

 

if($check_user) {

show something; 
}
 else { 
Show something else; 
}

Cheers,