Object to string conversion in JavaScript
<p>I was playing around with object to string conversion in JavaScript. All objects inherit two conversion functions - <code>toString()</code> and <code>valueOf()</code>. When JavaScript tries to convert object into string, it searches for the <code>toString()</code> implementation and then for <code>valueOf()</code> implementation. So I overrode the <code>toString()</code> and <code>valueOf()</code> in this way:</p>

<pre><code>var obj = {
x: 10,
y: 20,   
toString: function() {
    return "x = " + this.x + ", y = " + this.y;
},
valueOf: function() {
    return this.x + ", " + this.y;
}};
</code></pre>

<p>Concatenating the object literal with a string:</p>

<pre><code>console.log("hello " + obj);
</code></pre>

<p><strong>OUTPUT</strong> : <code>hello 10, 20</code></p>

<p>Shouldn't the output be : <code>hello x = 10, y = 20</code>?</p>

<p>Appreciate any help. </p>
