You can pass some parameter to a function used as callback in JavaScript.
These two options would look like this:
1 2 3 4 5 6 |
function firstfunction(callback) { // code here callback(arg1, arg2); } firstfunction(callbackfunction); |
Or
1 2 3 4 5 6 7 8 |
function firstfunction(callback) { // code here callback(); } firstfunction(function() { callbackfunction(arug1, arug2); }); |
Callback function with parameters in JavaScript Example
HTML example code:- Using the arguments variable like so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<html> <body> <script> function tryMe (param1, param2) { alert(param1 + " and " + param2); } function callbackTester (callback) { callback (arguments[1], arguments[2]); } callbackTester (tryMe, "Hello", "callback"); </script> </body> </html> |
Output:

Read more: – JavaScript callback function
Do comment on this topic if you have any doubts and suggestions.
Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version