lundi 7 mai 2018

Why does If statement throw an undefined error when I am checking if its undefined? [duplicate]

This question already has an answer here:

Why does my else if statement cause the parser to throw an undefined error? I know that it is undefined which is why I am checking, I want it to hit the else block in this case, because this function is used in mutiple places the data that is being passed in is not always the same. So I am trying to check which type of data is being passed in.

if(icon){
    dv.find(".mobCol>.image").html(generateIcon(icon));
}
else if(location[0].properties !== undefined){
    dv.find(".mobCol>.image").html(generateIcon(location[0].properties.image));
    data = location[0];
}
else{
    dv.find(".mobCol>.image").html(generateIcon(location.features[0].properties.image));
    data = location.features[0];
}

Aucun commentaire:

Enregistrer un commentaire