title: Using || to coalesce first non null value
body: <p>Here is a function:</p>
  
  <pre><code>function() {
  
      // if on wordpress site decipher if English or Français by using url path
      var lang = '';  
      var wp_path = document.location.pathname.match(/^\/(en|fr)\//)[0];
  
          if (wp_path == "/en/") {
          lang = "Français";}
          else if (wp_path == "/fr/") {
          lang = "English"; 
          }
  
      // if on ruby site decipher if English or Français by using querySelector on element
      var ruby_lang = document.querySelector('.menu--primary a[href*="lang="]').textContent.trim();
  
      // either lang or ruby_lang will be null, assign value to opp_language accordingly
      var opp_language = lang || ruby_lang;
  
  return opp_language;
  
  }
  </code></pre>
  
  <p>In the Chrome JS console this works if I type it line by line:</p>
  
  <p>E.g. on url <a href="http://www.example.com/en/" rel="nofollow">http://www.example.com/en/</a></p>
  
  <pre><code>var lang = '';  
          var wp_path = document.location.pathname.match(/^\/(en|fr)\//)[0];
  
              if (wp_path == "/en/") {
              lang = "Français";} // yes NOT English, it's opposite
              else if (wp_path == "/fr/") {
              lang = "English"; 
              }
  </code></pre>
  
  <p>Returns Français as expected.</p>
  
  <p>Then, when I'm on a page without a url path containing either en or fr I know that the variable "ruby_lang" will return either English or Français. I have verified this second part of the function works in the console.</p>
  
  <p>So the 3rd part is presumably the problem. My expectation is that at this point, either lang or ruby_lang are set to a truthy value. So:</p>
  
  <pre><code>// either lang or ruby_lang will be null, assign value to opp_language accordingly
          var opp_language = lang || ruby_lang;
  </code></pre>
  
  <p>But instead, whenever I run this function opp_language is undefined.</p>
  
  <p>Does the double bar || syntax behave in a different way than I understand?</p>