title: Symbol.toPrimitive vs Object.prototype.valueOf
body: <p>In ECMAScript 6, a new <code>Symbol.toPrimitive</code> symbol is introduced, which, when used as an object key, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol" rel="noreferrer">should define</a> a function to return the <em>primitive value</em> of an object:</p>
  
  <pre><code>let object = {
      aNumber: 0,
      [Symbol.toPrimitive]() {
          return this.aNumber;
      }
  };
  
  object.aNumber = 5;
  console.log(object + 2) // 7
  </code></pre>
  
  <p>However, there is also the <code>Object.prototype.valueOf</code> function, which, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf" rel="noreferrer">according to the documentation</a>, could be redefined to convert an object to the primitive value:</p>
  
  <pre><code>let object = {
      aNumber: 0,
      valueOf() {
          return this.aNumber;
      }
  };
  
  object.aNumber = 5;
  console.log(object + 2) // 7
  </code></pre>
  
  <p>So, which of these ways to convert an object to its primitive value should be used in ES6 when defining a new object?</p>