I have a boolean function here called checkURL that checks if a picture has 100 x 100 pixels. If so it returns true. There is an asynchronous call within the function to check the size of the image.
function checkURL(url, callback) {
var valid;
var img = new Image();
img.src = url;
img.onload = function (callback) {
valid = callback(img.width, img.height);
};
console.log(valid);
return valid;
}
function nextStep(w, h) {
if (w == 100 && h == 100) {
return true;
} else {
return false;
}
}
var pic_valid = checkURL(a_url, nextStep);
I am getting the error:
callback is not defined
within the checkURL function. I am also worrying that the variable valid within checkURL will end up being invalid.
ADDITIONAL EDIT: If I add console.log(valid); before returning valid I get undefined. Is this expected?