What is $watch in AngularJS?

$watch is used to monitor changes to a variable on the $scope. When the variable changes, a callback is triggered.

$scope.$watch('name', function(newVal, oldVal) {
  console.log('Name changed from', oldVal, 'to', newVal);
});