title: Selenium Javascript executor returns null
body: <p>I have the following JavaScript code returning <code>null</code> when ran through Selenium <code>JavascriptExecutor</code>. However, the same code when ran in Firefox developer console returned a value.</p>
  
  <pre class="lang-js prettyprint-override"><code>function tmp(){
      var attrb = jQuery(jQuery("[name='q']")[0]).attr('type');
      if(typeof attrb !== 'undefined' &amp;&amp; attrb !== false){
          return attrb;
      } else {
          return '';
      }
  }
  
  tmp();
  </code></pre>
  
  <p>The below is my WebDriver code with the JS the same as above:</p>
  
  <pre class="lang-java prettyprint-override"><code>JavascriptExecutor jsExec = (JavascriptExecutor)driver;
  Object inpType = 
         jsExec.executeScript("function tmp(){...}tmp();");
  System.out.println("Type: " + inpType);
  </code></pre>
  
  <p>Above outputs <code>null</code> instead of "text" string. Any ideas? </p>