Callback function with parameters JavaScript | Example code

You can pass some parameters to a function used as a callback in JavaScript.

Here are two options to use a callback function in python.

function firstfunction(callback) {
    // code here
    callback(arg1, arg2);



function firstfunction(callback) {
    // code here

firstfunction(function() {
    callbackfunction(arug1, arug2);

Callback function with parameters in JavaScript Example

HTML example code:- Using the arguments variable like so:


		function tryMe (param1, param2) {
			alert(param1 + " and " + param2);

		function callbackTester (callback) {
			callback (arguments[1], arguments[2]);

		callbackTester (tryMe, "Hello", "callback");


Callback function with parameters JavaScript

Read more: JavaScript callback function

Do comment on this topic if you have any doubts and suggestions.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.