title: Node.js access the value of variable from another function
body: <p>How do i get the value of myObject.myname, myObject.myage from the function getval? It returns undefined when i console.log it. Btw I'm using node js. Thanks.</p>
  
  <pre><code>    var post = http.request(options, function(res) {
          res.setEncoding('utf8');
          res.on('data', function (data) {
          console.log('Response: ' + data);
  
      var myObject = JSON.parse(data);
  
          console.log('----------------------------------------------');
          console.log(myObject.myname);
          console.log(myObject.myage);
          console.log('----------------------------------------------');
          });
      });
  
      function getVal() {
          //some code here
          console.log(myObject.myname);
          console.log(myObject.myage);
      }
  </code></pre>