Function returning the contents of an object
<p>I have written the following code:</p>

<pre><code>function return_list_node(v,r)
 {
 return {value: v, pointer: r};
 }
console.log(return_list_node(10,return_list_node(20,null)));
</code></pre>

<p>I expected it to return <code>{value: 10, pointer: {value: 20, pointer: null}}</code>. Instead, the function returns <code>Object {value: 10, pointer: Object}</code>.</p>

<p>I know that it is not a console.log issue as I watched the execution of the code in my debugger - and the return value was indeed an object type.</p>

<p>I have tried other methods, as:</p>

<pre><code>function return_list_node(v,r)
 {
 var ret=
  {
  value: v,
  pointer: r
  };
return ret;
 }
console.log(return_list_node(10,return_list_node(20,null)));
</code></pre>

<p>but the issue remains. For example, the first call to return_list_node() will return <code>Object {value: 20, pointer: null}</code>.</p>

<p>If that helps, my main source of information is <a href="http://eloquentjavascript.net/" rel="nofollow">Eloquent Javascript</a>. In this book, the author gives <a href="http://eloquentjavascript.net/04_data.html#c_2uZIZgWSsu" rel="nofollow">a certain example</a>:</p>

<pre><code>function randomPointOnCircle(radius) {
  var angle = Math.random() * 2 * Math.PI;
  return {x: radius * Math.cos(angle),
          y: radius * Math.sin(angle)};
}
console.log(randomPointOnCircle(2));
// → {x: 0.3667, y: 1.966}
</code></pre>

<p>And indeed, executing it in his site gives <code>{x: -0.2914551368496415, y: -1.9786495149985397}</code>. While if I run the above code locally, I receive <code>Object {x: 1.9649681395718306, y: 0.37269318543222546}</code>.</p>

<p>I have validated that in <a href="http://eloquentjavascript.net/04_data.html#c_F73m7OkLk8" rel="nofollow">this excersise</a> (in the sandboxed environment of the site) my code (used in <code>prepend()</code>) indeed returns what I expected it to return ( <code>{value: 10, rest: {value: 20, rest: null}}</code> ), and not an Object.</p>

<p>Why the discrepancy between the sandboxed environment and my Google Chrome 48? What is the proper/expected behaviour of a function which returns an object?</p>

<p>Thank you in advance.</p>