JQuery: Callback functions without arguments

Callback without Arguments

If a callback has no arguments, you can pass it in like this:

$.get( "myhtmlpage.html", myCallBack );
When $.get() finishes getting the page myhtmlpage.html, it executes the myCallBack() function.

Note: The second parameter here is simply the function name (but not as a string, and without parentheses).

so i was looking at learn.jquery.com and i ran across this feature about callback without arguments.

I was wondering when i would actually use something like this.

<!DOCTYPE html>
<!-- saved from url=(0016)http://localhost -->

function mySandwich(param1, param2, callback) {
    alert('Started eating my sandwich.\
It has: ' + param1 + ', ' + param2);
    callback();  /* what does this callback function do exactly */
mySandwich('ham', 'cheese', function() {
    alert('Finished eating my sandwich.');






For example in this code, what exactly does this callback function do, because i don’t even see this callback function defined?

callback(); // what does this do in the code above , since i don’tsee any action defined for this.

In the code you providecd callback() displays the alert as that’s what the function passed as the callback parameter does.

I see now. thank you.