Use of the identity function in JavaScript
问题 I use the identity function in all my JavaScript programs: function identity(value) { return value; } The reason is that I often need differentiate between primitives types ( undefined , null , boolean , number and string ) and object types ( object and function ) as returned by the typeof operator. I feel using the indentity function for this use case very succuint: if (new identity(value) == value); // value is of an object type if (new identity(value) != value); // value is of a primitive