title: 'this' in JavaScript behaves differently in node and chrome console
body: <p>running the same code in different environments produces different results<a href="https://i.stack.imgur.com/4RqJY.png" rel="nofollow noreferrer">1</a></p>
  <p>try running the code below in chrome console and on node js, the first produces <code>snehal</code> <code>snehal</code> and the other <code>undefined</code> <code>undefined</code></p>
  <pre><code>this.name = &quot;snehal&quot;;
  
  function meme() {
    console.log(this.name);
    function mem() {
      console.log(this.name);
    }
    mem();
  }
  
  meme(); 
  </code></pre>
  <p>The basic idea about <code>this</code> in JavaScript is that it points/refers to the object that contains it, so in the chrome console we can expect the inner mem function <code>this</code> to be === to the meme function this, but the same is not consistent in the node environment.</p>