Let's say that you want to insert a node somewhere in the DOM, but if it is a string, then you want to insert it automatically as a text node. Here is how you might want to achieve this:
function checkElem(elem)
{
// If only a string was provided, convert it to a Text Node
return elem && elem.constructor == String ?
document.createTextNode(elem) : elem;
}
Borrowed from the book Pro JavaScript Techniques by John Resig.