title: How to send data from express backend to ejs front end?
body: <p>I am trying out a Tutorials website and in that some of my pages need to send tutorials object, video object, user object depending on which route they landed. So, is it necessary to send null object even if I don't need them on the front end? I am extracting these backend objects in script tag and assign it to window object for use in angular client.</p>
  
  <p>Here are some sample codes.</p>
  
  <pre><code>// layout.ejs   common to all front end views
  &lt;script&gt;
  window.user = &lt;%- typeof user !== 'undefined'? JSON.stringify(user) : null %&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>Backend sends this type of code:</p>
  
  <pre><code>res.render('/partials/index', {
      title: 'Title'
  });
  </code></pre>
  
  <p>But when I don't send user as null, it throws ReferenceError: user not defined. Why is it so? I am checking in the script tag if it is undefined, I am using null. Is it wrong?</p>
  
  <p>If we need to explicitly send null from backend, then it seems awkward to send null everytime even though I don't need it. What is right way to do it?</p>