I am a beginning javascript programmer. I have been trying to understand asynchronous javascript but I wanted to clear up a couple of things.
I understand that javascript runs in a single thread and that you can use callback functions to make your code asynchronous, but I am confused about what makes a callback function asynchronous or not.
A lot of the async callbacks seem to follow a pattern where a function has as its parameters a certain action and then a callback function which is to execute when that action is complete:
jQuery.get('page.html', function (data) {
console.log("second");
});
console.log('first');
What is it specifically that makes the callback in the parameter here execute at a later time? Is it that the get method here is pre-defined as some sort of a special method (because it fetches a file) that if you pass a function as a second parameter, it behaves in a asynchronous manner?
How can you make functions that you would write yourself asynchronous?
Thanks