title: Can I avoid that $scope.$watch returns an undefined value?
body: <p>When I observe a scope variable in Angular via <code>$scope.$watch</code>, it seems to be <code>undefined</code> only at the first call of the watch function.</p>
  
  <p>Is it possible to rewrite my code to avoid the unnecessary check for <code>undefined</code>?</p>
  
  <p>Here is a minimal example:</p>
  
  <p>1) <a href="http://jsfiddle.net/T7LTv/4/" rel="nofollow noreferrer">jsfiddle</a></p>
  
  <p>2) HTML:</p>
  
  <pre><code>&lt;div ng-app="MyApp"&gt;
     &lt;div ng-controller="MyCtrl"&gt;Enter some text:
        &lt;input type="text" ng-model="text" size="30" /&gt;
        &lt;p&gt;You entered: {{text}}&lt;/p&gt;
        &lt;p&gt;Length: {{textLength}}&lt;/p&gt;
     &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>3) Javascript:</p>
  
  <pre><code>angular.module('MyApp', []).controller(
    'MyCtrl', function ($scope) {
      $scope.textLength = 0;
      $scope.$watch('text', function (value) {
        if (typeof value !== 'undefined') {
          $scope.textLength = value.length;
        } else {
          $scope.textLength = 'observed value is undefined';
        }
      });
  });
  </code></pre>