title: Accessing passed EJS variable in Javascript file
body: <p>RESTful routes js file:</p>
  
  <pre><code>// index route - show all todos
  router.get("/", middleware.isLoggedIn,function(req,res) {
    Todo.find({ "author.id" : req.user._id}, function(err, allTodos) {
      if(err) {
        console.log(err);
      } else {
        res.render("todo/index", {todos: allTodos});
      }
    });        
  });
  </code></pre>
  
  <p>My index.ejs file has:</p>
  
  <pre><code>&lt;script src="/scripts/todoCalendar.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>at the end of the <code>body</code> tag and I want to access the passed variable <code>todos</code> inside my todoCalendar.js file.
  I tried putting</p>
  
  <pre><code>&lt;script&gt;
    var x= &lt;%= todos %&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>but it says <code>x</code> is undefined when i try to do a <code>console.log(x)</code> inside my todoCalendar.js file.</p>
  
  <p>Any help is greatly appreciated.</p>