When you do this
alert(sayMyName()), you're passing the return value of the
sayMyName() function to the
alert() function.
When you do this
alert(sayMyName), you're passing the
sayMyName() function to the
alert() function.
When you pass a function to
console.log(), it will print the
string value of the function to the console.
Similarly, when you pass a function to
alert(), it will display the string value of the function.
For example, when you run this code,
it will display an alert box with the message
A callback function is a function that is passed to another function as a parameter and then called in the function at an appropriate time. For example,
caller() accepts
myCallback() as a parameter and then
caller() calls
myCallback() at an appropriate time. This typically happens with event handling code like
addEventListener() which may accept
myCallback() as a parameter and then call
myCallback() as a result of an event occurring.
For example, when you run this code,
it will display an alert box with the message