title: JavaScript Try Catch
body: <p>I'm looking at some code on a website that hides / shows content on a click.</p>
  
  <pre><code>    function expando() {
          try {
              if (document.getElementsByClassName) {
                  var e = document.getElementsByClassName("expandlink"); 
                  t = 0;
              } else {
                  var e = document.querySelectorAll(".expandlink"),
                      t = 1;
              };
              if (null != e) {
                  for (var a = 0; a &lt; e.length; ++a) e[a].onclick = function() {
                      return OpenClose(this), !1
                  };
                  if (1 == t)
                      for (var a = 0; a &lt; e.length; ++a) {
                          var n = e[a].href,
                              r = n.indexOf("#"),
                              i = n.substr(r + 1),
                              l = document.getElementById(i);
                          l.className = l.className + " expandtargetIE8"
                      }
              }
          } catch (o) {}
      }
  
      function OpenClose(e) {
          try {
              var t = e.href,
                  a = t.indexOf("#"),
                  n = t.substr(a + 1),
                  r = document.getElementById(n);
              r.className = "expandtarget" === r.className ||
                  "expandtarget expandtargetIE8" === r.className ?
                  "expandtargeted" : "expandtarget expandtargetIE8",
                  e.className = "expandlink" === e.className ?
                  "expandlink expandlinked" : "expandlink"
          } catch (i) {}
      }
      window.onload = function() {
          expando()
      };
  </code></pre>
  
  <p>Here is the JS Fiddle. </p>
  
  <p><a href="https://jsfiddle.net/amykirst/3hbxwv1d/" rel="nofollow">https://jsfiddle.net/amykirst/3hbxwv1d/</a></p>
  
  <p>I've never seen the JavaScript try...catch statement. I looked at some tutorials, and they all say that they are for error testing. Why would it be used here? </p>
  
  <p>It doesn't look like the catch actually does anything. </p>
  
  <p>Note: this code had been minified. I used an online tool to unminify it.</p>