Is just a function that executes after one other function that calls it, finishes?
Please I know (almost) nothing about programming, and I find it quite hard to find a proper newbie answer or explanation about what does this means.
Can I request a try from stackoverflow gurus?
In general, a callback function is used once another function you have called finishes (just like you stated in your question). A good example of this is AJAX requests: most libraries have a function that allows you to send a request to the server in the background without refreshing the page (this uses AJAX). You generally provide two callback functions to this AJAX function: a success function, and a failure function.
If this request succeeds, it calls the success function so that your code can do what it needs; for instance, it might refresh part of the page, do some sort of animation, or alert the user that their information was saved. On the other hand, if it failed, the callback function would probably alert the user that their data was not saved and that they should try again.
Callback functions allow library developers to create very generic code that others can use and then customize to their needs.
Below is some jQuery code to show you the example above (this code won’t work as the URL doesn’t exist):
EDIT: At the beginning, I said, “In general…”. In reality, callbacks are used for much more than just when a function finishes. Like stated in other answers, it can be used anywhere inside of a function: beginning, middle, end. The basic idea is that the developer of the code may not know how YOU are going to use HIS code. So, he makes it very generic and gives you the ability to do whatever you need with the data.
A good example of this is the jQuery.each method which allows you to pass in a callback that will be executed on each of the elements in the “array” (I say array because it can actually iterate over many things which may or may not be actual arrays).
So, we can see from this example that the developers of jQuery implemented the .each method and allow us to do whatever we want to to each link that it is called upon.