title: Passing variable in onclick: Uncaught SyntaxError: Unexpected indentifier
body: <p>I'm trying to pass an object to a function in the onclick event. If I run the code below, I get <code>Uncaught SyntaxError: Unexpected indentifier</code>. If I uncomment the <code>JSON.stringify</code> line, and use <code>taskAsJson</code> in place of <code>task</code>, I get the same error.</p>
  
  <pre><code>$.each(tasks, function (index, task) {
      //var taskAsJson = JSON.stringify(task);
      items.push('&lt;li&gt;&lt;a href="#" onclick="showTask(' + task + ');"&gt;' + task.Description + '&lt;/a&gt;&lt;/li&gt;');
  });
  </code></pre>
  
  <p>However, if I hard-code a value, like 5, it works and 5 gets passed to the function.</p>
  
  <pre><code>$.each(tasks, function (index, task) {
      items.push('&lt;li&gt;&lt;a href="#" onclick="showTask(' + 5 + ');"&gt;' + task.Description + '&lt;/a&gt;&lt;/li&gt;');
  });
  </code></pre>
  
  <p>Why do I get that error when I try to pass my object? What do I need to change in order to be able to pass <code>task</code> or <code>taskAsJson</code>?</p>
  
  <p>Note: items is an array that gets used to update a div and listview:</p>
  
  <pre><code>$('#appTasks').append(items).listview('refresh');
  </code></pre>