title: JavaScript: Deep comparison recursively: Objects and properties
body: <p>Today I finished reading Ch. 4 in Eloquent JS and I'm struggling to understand how to perform a deep comparison between objects and their properties, particularly through the use of a recursive call. I know my solution below is quite naive and a bit bulky, but I'm trying to wrap my head around all these new things I'm still learning! Just less than a month in on programming :) I would appreciate any tips and help you might have in improving the code and also if you could help me better understand the recursion that needs to occur. Thank you in advance!</p>
  
  <p><ul>
  <li>Question (Eloquent JS 2nd Ed, Chapter 4, Exercise 4):</p>
  
  <blockquote>
    <p>Write a function, deepEqual, that takes two values and returns true
    only if they are the same value or are objects with the same
    properties whose values are also equal when compared with a recursive
    call to deepEqual.</li>
    </ul>
    <strong>Test Cases:</strong></p>
  </blockquote>
  
  <pre><code>var obj = {here: {is: "an"}, object: 2};
  var obj1 = {here: {is: "an"}, object: 2};
  console.log(deepEqual(obj,obj1));
  </code></pre>
  
  <p><strong>My Code:</strong></p>
  
  <pre><code>  function objectTester(x) {
        if (typeof x === 'object' &amp;&amp; x !== null)
          return true;
      }
  
      function deepEqual(valOne, valTwo) {
        if (valOne === valTwo) return true;
  
        var comp1 = objectTester(valOne);
        var comp2 = objectTester(valTwo);
  
        if (comp1 === comp2) {
          var count1;
          var count2;
          for (var prop in valOne) {
              count1++
              return count1;
          }
          for (var prop in valTwo) {
              count2++
              return count2;
          }
          if (count1 === count2) {
  
          // This is where I'm getting stuck, not sure how I can recurisvely compare
          // two arguments that are to be compared. 
        }
      }
  </code></pre>