title: Use of the identity function in JavaScript
body: <p>I use the identity function in all my JavaScript programs:</p>
  
  <pre><code>function identity(value) {
      return value;
  }
  </code></pre>
  
  <p>The reason is that I often need differentiate between primitives types (<code>undefined</code>, <code>null</code>, <code>boolean</code>, <code>number</code> and <code>string</code>) and object types (<code>object</code> and <code>function</code>) as returned by the <code>typeof</code> operator. I feel using the indentity function for this use case very succuint:</p>
  
  <pre><code>if (new identity(value) == value); // value is of an object type
  if (new identity(value) != value); // value is of a primitive type
  </code></pre>
  
  <p>The identity function is much smaller and simpler than the following code:</p>
  
  <pre><code>function isObject(value) {
      var type = typeof value;
      return type == "object" || type == "function";
  }
  </code></pre>
  
  <p>However on reading my code a friend of mine complained that my hack is misleading and more computationally expensive than the above alternative.</p>
  
  <p>I don't want to remove this function from any of my programs as I believe it's an elegant hack. Then again I don't write programs solely for myself. Is there any other use case for the identity function in JavaScript?</p>