How to get title of taxonomy term referenced in node

Get title of referenced taxonomy term on node in Drupal 9 and Drupal 10

Include the Node class

use Drupal\node\NodeInterface;

$node = Drupal::routeMatch()->getParameter('node');

$title = $node->field_machine_name->entity->title->value;

Category