if (foo !== null) evaluates to true, even when foo is null
<p>In javascript I have an option for log output that allows an element/selector to be used to specify where to output log/error messages. The output is formatted upon initialization like so:</p>

<pre><code>var $messageOutput = options.messageOutputElement ? $(options.messageOutputElement) : null;
</code></pre>

<p>and it is used later on through a log function:</p>

<pre><code>function outputMessage(msg)
{
    if ($messageOutput !== null)
    {
        messageNum++;
        var $messageOutput = $(options.messageOutputElement);
        var html = $messageOutput.html();
        html += '&lt;b&gt;' + messageNum + '&lt;/b&gt;&lt;br/&gt;' + msg + '&lt;br/&gt;';
        $messageOutput.html(html);
        $messageOutput.scrollTop($messageOutput[0].scrollHeight);
    }
}
</code></pre>

<p>The problem is that even when $messageOutput === null, the if statement inside outputMessage() falls through. I've verified with Chome's debugger that $messageOutput indeed equals null. And indeed it steps into the if statement anyway.</p>

<p>Can anyone give me any insight as to why this might be happening? Thanks in advance for any input on this matter.</p>
