title: Node.js V8 pass by reference
body: <p>I wonder how memory is managed in V8. Take a look at this example:</p>
  
  <pre><code>function requestHandler(req, res){
    functionCall(req, res);
    secondFunctionCall(req, res);
    thirdFunctionCall(req, res);
    fourthFunctionCall(req, res);
  };
  
  var http = require('http');
  var server = http.createServer(requestHandler).listen(3000);
  </code></pre>
  
  <p>The <code>req</code> and <code>res</code> variables are passed in every function call, my question is:</p>
  
  <ol>
  <li>Does V8 pass this by reference or does it make a copy in memory?</li>
  <li><p>Is it possible to pass variables by reference, look at this example.</p>
  
  <pre><code>var args = { hello: 'world' };
  
  function myFunction(args){
    args.newHello = 'another world';
  }
  
  myFunction(args);
  console.log(args);
  </code></pre>
  
  <p>The last line, <code>console.log(args);</code> would print:</p>
  
  <pre><code>"{ hello: 'world', newWorld: 'another world' }"
  </code></pre></li>
  </ol>
  
  <p>Thanks for help and answers :)</p>