Question: I'm trying to check if something is undefined in javascript (data[index]) and showing an alert if it is. However, it doesn't seem to be hitting.

I've tried:

```
  if(data[index]){ }

```

And i've tried:

```
  if (typeof(jsVar) == 'undefined') { }

```

However, neither of them seem to work and I get:

```
Uncaught ReferenceError: index is not defined 

```

Full code:

```
function myAlerts(data)
{
    $("#alertsListMissingPets").empty();
    $.mobile.loading( 'hide', { theme: "b", text: "Loading", textonly: false});
    if(data[index].Name){
    $.each(data, function(index) {
        console.log(data[index].LostDate)
        $("#alertsListMissingPets").append(" <li><a data-lostid='"+ data[index].LostKey + "' data-custom='"+ data[index].AnimalKey + "' href=\"#\">"+ data[index].Name + " <span class=\"ui-li-count\">"+ data[index].Distance + "</span></a></li>");
    });
    $("#alertsListMissingPets").listview('refresh');
    } else {
        function alertDismissed() {
            $.mobile.changePage("#mainpage");
        }
        navigator.notification.alert('No missing pets in your area!', alertDismissed, 'Good News', 'Okay' );
    }
}

```

Answer: 
Clearly, the error state that `index` is undefined. Take a look at your code :

```
if(data[index].Name){ //Check something with index here
$.each(data, function(index) { //Define index here

```

You can't use `index` outside the loop...
As you can see from the error **index** variable is **undefined**.
You should be doing the following

```
typeof(index) == 'undefined'

```

or 

```
typeof(index) != 'undefined'

```