title: Variable returns [object HTMLParagraphElement]
body: <p>I am having difficulties working with variables in jQuery.
  The var would need to return the width of the window.
  To test this I wrote some code where the width is displayed in a paragraph when I hit a button:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var update = function() {
    width = $(window).width();
  }
  
  $(document).ready(
    function() {
      $('button').click(
        function() {
          update,
          $('#width').text(width)
        }
      )
    }
  )</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;p id="width"&gt;Width&lt;/p&gt;
  &lt;button&gt;test&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I get "[object HTMLParagraphElement]" instead of the value of the width.
  I don't understand why, because when I run this code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var width = $(window).width();
  
  $(document).ready(
      function () {
          $('button').click(
              function () {
                  $('#width').text(width)
              }
          )
      }
  )</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;p id="width"&gt;Width&lt;/p&gt;
  &lt;button&gt;test&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I do get the value without any problems. But in this way I can't update the variable after resizing the window (I think because the variable is only declared at the loading of the page.)</p>
  
  <p>This probably is a real newbe problem, but I am very eager to learn...</p>