I am facing a lot of issues while populating data in the DOM, because of there are no values in the objects or arrays, which I want to use.
For example, I have an object:
var obj = {
name: 'rajat',
age: 20
}
and I am populating data on HTML Elements Dynamically, Like below:
<p id='paragraph'></p>
var data = document.getElementById('paragraph');
data.innerHTML = obj.name;
Now, I just want to add condition before assigning value to HTML element, I am confused by if(obj.a)
and if(obj.a!=undefined && obj.a!=null)
.
Can anyone please explain the difference between the two?