Javascript Empty String vs (null and undefined)
<p>I have a object</p>

<pre><code>var data = {1:undefined,2:null,3:10,4:""}
</code></pre>

<p>I want to replace all the undefined and null values by 0. I am using the following code to do that:</p>

<pre><code>for (var index in data) {
    if (!data[index]) {
        data[index] = 0;
    }
}
</code></pre>

<p>Result I am expecting is :  <code>{1:0,2:0,3:10:4:""}</code> 
But Result is :  <code>{1:0,2:0,3:10:4:0}</code> because it is considering empty string as null. Is it known behavior ? </p>

<p>I can check it by using 
<code>(if(data[index] == undefined || data[index] == null))</code> 
But I wanted to know the behavior of the above solution.</p>