title: Are DOM elements passed by reference to console.log?
body: <p>I'm not even sure exactly what I'm asking here. I just know it isn't what I expected. </p>
  
  <p>I have a page script (see below) that grabs a reference to an element by its ID, then calls a few functions on it. Each function logs the element (or its <code>textContent</code>) to the console, modifies the text contents, then calls the next function. What confuses me is how those changes are logged.</p>
  
  <p><a href="http://jsbin.com/mexuzeramave/1/edit" rel="nofollow">If I log <code>element.textContent</code>, I get the behavior I expected</a>: Each log prints the string as left by the previous function.</p>
  
  <p><a href="http://jsbin.com/zujowakitapu/2/edit?html,js,console,output" rel="nofollow">If I log the element itself, I get a different behavior</a>*: Each log outputs the element in its final state, not its state when the log was called. </p>
  
  <p>This leads me to think that the element is passed by reference, resulting in all the references being updated together as the script continues, while the element's text contents are logged by value.</p>
  
  <p>If this is true, how do I know which behavior to expect? Are all DOM references passed by reference, while strings (primitives) by value? As I understand it, JavaScript passes objects by reference and primitives by value. Is that what’s happening here?</p>
  
  <p>*The output from JS Bin is far more verbose that Chrome gives—but it does describe the elements as of type <code>object</code>, however. The full code I was using is (using <code>element.textContent</code>, not <code>element</code>) below.</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;p id="paragraph"&gt;First paragraph&lt;/p&gt;
  &lt;script&gt;
    (function () {
      'use strict'
  
      var one = function () {
        console.log(example.textContent)
        example.textContent = example.textContent.replace('paragraph', 'call')
        two()
      }
      var two = function () {
        console.log(example.textContent)
        example.textContent = example.textContent.replace('First', 'Second')
        three()
      }
      var three = function () {
        console.log(example.textContent)
        example.textContent = example.textContent.replace('Second', 'Third')
        console.log(example.textContent)
      }
  
      var example = document.getElementById('paragraph')
      console.log(example.textContent)
      one()
    })()
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>