i don’t understand where your function(data) is getting it’s data from. where is the function being called?
JS is an odd language in many ways. Most languages are synchronous by default - they wait until something is done before doing the next thing. But on the web you need to often request things and you don’t know when you will get a reply so you can’t wait. That is what asynchronous functions are for and that is where JS shines.
$.getJSON(urlForismatic, function(data) {
console.log("\n\n\n*** forismatic $.getJSONexample...");
console.log(data);
showInfo("Example of forismatic API using $.getJSON", data.quoteText, data.quoteAuthor, data);
}); // $.getJSON
When the JS gets to this code, it knows that it is making an asynchronous call out into the internet. It says: OK, you go get the data and I’m going to get back to execute code, but if you want to give me a function, you can call that when you get back, a “call back” function if you will. So, in our code, we have constructed and anonymous function (no name) and sent that, as the second argument of $.getJSON. We could have named and created a function somewhere else, but doing it this way is common enough.
So, getJSON goes off and gotten it’s data. By default, we know that it will send it back in an object. In our anonymous function, we know a parameter is coming in. We’ve chosen to accept it under the name of “data”, but could have called it anything. We know that getJSON sends back a data object and that’s what we’re calling it.
Since JS has almost certainly finished the rest of the code and is patiently waiting for events or other callbacks, it sees that that getJSON call is returning and feeds that data into the anonymous function it stored as a call back for this. That function now has access to that data.
Again, JS is a strange language in some ways. The way it passes functions around like cans of beer is one of them. A very common use for that is callback functions. A big chunk of your confusion seems to come from not understanding CBs. Yeah, I remember they confused the hell out of me. I might suggest watching some youtube videos about JS CBs. Really, it’s strange at first, but once it clicks, it’s kind of cool. Just work at it, you’ll get it. But CBs are hugely important for JS so don’t skip over it.