title: javascript function execution inside jade template
body: <p>I am new to nodejs and trying to create a jade file for the html content <code>myfile.jade</code>:
  Here are the contents of the file:</p>
  
  <pre><code>extends layout
  block content
     script
       function capitalize(s) { 
         console.log("Testing js exec");
         return s.charAt(0).toUpperCase() + s.slice(1); 
       };
    table
      - each item in list
        tr
          td
            a(href="/collection/#{item.name}") #{capitalize(itemName)}
  </code></pre>
  
  <p>However, when running it throws the following error:</p>
  
  <pre><code>Error: mweb/views/collections.jade:8
      6|   script
      7|     function capitalize(s) { 
    &gt; 8|       console.log("Testing js exec");
      9|       return s.charAt(0).toUpperCase() + s.slice(1); 
      10|     };
  </code></pre>
  
  <p><code>unexpected text ;</code></p>
  
  <p>If I remove console.log, it throws the error saying:</p>
  
  <pre><code>TypeError: mweb/views/collections.jade:18
    &gt; 18|             a(href="/collection/#{item.name}") #{capitalize(itemName)}
  </code></pre>
  
  <p>As far as I realized, capitalize is being called during the jade compilation and the function is not available as the script tag is also compiled into the html. What is the best way for me to have this call evaluated on 
  a) server side or 
  b) client side?</p>
  
  <p>Thx</p>