I understand(somewhat) that the callback parameter in the getJSON function is a placeholder for a later function but how is the anonymous function that's passing json able to see/associate the variable data if it's passing as an argument itself? Only been learning JS for a few weeks and it's pretty intense.
let people = 'http://api.open-notify.org/astros.json';
let show = document.getElementById('people');
function getJSON(url, callback) {
const xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = () => {
if(xhr.status === 200) {
let data = JSON.parse(xhr.responseText);
return callback(data);
}
};
xhr.send();
}
getJSON(people, (json) => {
console.log(json);}
);