0

This question has been answered earlier. I checked multiple question in SO but i am not able to understand that properly. Apologies for that.

I am using ajax and data is coming from database.

if(data.count > 0 ){
    $.each(data.content, function(key, value ){
if((value.technology) != ''){
 html+='<button class="form-control" disabled>'+value.technology+'</button>&nbsp;';
                            }

i also tried this

if((value.technology6 !== 'null')){
     alert(value.technology6);
  html+='<button class="testsss testss" disabled>'+value.technology6+'</button>&nbsp;';
                            }

and tried this as well

if(!(value.technology7)){
 html+='<button class="testsss testss" disabled>'+value.technology7+'</button>&nbsp;';
  }

problem is i am getting null as output. i am not sure what am i doing wrong and what is the proper way to check null and undefined.

Thanks for your advise.

Roxx
  • 3,738
  • 20
  • 92
  • 155

2 Answers2

0

please check if value and data are not null or undefined , then write them in alert() function to see what alert you are getting like alert(data.content); or alert(value) ..

else check of null is correct. to check undefined you have to check like

if(data.content != undefined){
// your code here 
}

if you can more elaborate what is in there data and value , might help to solve your problem more appropriately

Rishi
  • 1
  • 1
0

Check Undefined

if(x != undefined)
{
    //x is defined
} else {
    //x is not defined
}

Check Null

if(y != null)
{
    //y is not null, we can do stuff
} else {
    //uh-oh, y is null
}

Also:

z = null;
w = undefined;
console.log(z == w); //Returns true