title: defined undefined null and .scrollTo
body: <p>I am trying to find when a link that has an href with the value of #target to scroll to that div with the id with the target. If it doesn't exist I want it to return to the index of the site. I have searched and researched and experimented but no success. Thanks in advance </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(function() {
          $('body').on('click', "a.page-scroll", function(event) {
              var $anchor = $(this);
              var $id = $anchor.attr('href');
              var $fid = $($id).length;
              console.log('anchor:' +  $anchor + 'id:' + $id + '$fid:' + $fid);
              if(typeof $id != 'undefined' || $id === null) {
                  $('body').stop().animate({
                  scrollTop: $($id).offset().top
              }, 1500, 'easeInOutExpo');
              event.preventDefault() 
              }
              else {
                 window.location.href = "index.html"; 
              }
          })
      });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;a class="page-scroll" href="#target1"&gt;link 1&lt;/a&gt;
  &lt;a class="page-scroll" href="#target2"&gt;link 2&lt;/a&gt;
  
  &lt;div id="target1"&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>