Question: I have declared this function in .js file and calling it in .html file.

```
function getTotalPages() {
    var valuePage;
    $.getJSON('Data/product.json').
        done(function(data) {
        $.each(data, function(key, value) {
                valuePage=value;
            });
        });
    //alert('out');
    return valuePage;
}

```

The above function returns the "undefined" without "alert", with alert it is working good. Can any one help me on this.

Thank you
In advance.

Answer: 
This issue has been answered a thousand times. It's about 'there is no way to return any value from an asynchronous request'. Everything you want to do with `valuePage` you should do inside the `done` callback.
AJAX is asynchronous, by the time you close the alert message the returned value will be resolved, but without the alert it would be too early. You can either make a synchronous request or use a callback.