Passing a function as a parameter in JavaScript Last Updated : 13 Jun, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we will pass a function as a parameter in JavaScript. Passing a function as an argument to the function is quite similar to passing a variable as an argument to the function. So variables can be returned from a function. The below examples describe passing a function as a parameter to another function. Example 1: This example passes a function geeks_inner to the function geeks_outer as an argument. JavaScript function geeks_inner(value){ return 'hello User!'; } function geeks_outer(func){ console.log(geeks_inner()); } geeks_outer(geeks_inner); Outputhello User! Example 2: This example passes a function geeks_inner along with an argument 'Geeks!' to the function geeks_outer as an argument. JavaScript function geeks_inner(value) { return 'hello ' + value; } function geeks_outer(a, func) { console.log(func(a)); } geeks_outer('Geeks!', geeks_inner); Outputhello Geeks! Example 3: Here in this example, a smaller function is passed as an argument in the sayHello function. So here we are passing a smaller function address to the function sayHello. JavaScript function sayHello(param) { console.log("hello", param); param(); return "Hiii Geeks for Geeks" } // Function address function smaller() { console.log("Is everything alright") } // Function call const returnHello = sayHello(smaller) console.log(returnHello) Outputhello [Function: smaller] Is everything alright Hiii Geeks for Geeks Comment More infoAdvertise with us Next Article Passing a function as a parameter in JavaScript P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies javascript-functions JavaScript-Questions Similar Reads JavaScript Passing parameters to a callback function Callback FunctionPassing a function to another function or passing a function inside another function is known as a Callback Function. In other words, a callback is an already-defined function that is passed as an argument to the other code Syntax:function geekOne(z) { alert(z); }function geekTwo(a, 2 min read How to pass an array as a function parameter in JavaScript? Here are different ways to pass an array as a function paramter in JavaScript.1. Using apply() MethodThe apply() method invokes a function with a specified `this` value and an array of arguments. It takes two parameters: the first is the `this` context for the function, and the second is an array of 2 min read How to pass image as a parameter in JavaScript function ? We all are familiar with functions and their parameters and we often use strings, integers, objects, and arrays as a parameter in JavaScript functions but now will see how to pass an image as a parameter in the JavaScript functions. We will use vanilla JavaScript here. Approach: First, create a func 2 min read JavaScript Function Parameters Function parameters are variables defined in the function declaration that receive values (arguments) when the function is called. They play a key role in making functions reusable and dynamic.Values are assigned to parameters in the order they are passed.You can assign default values to parameters 2 min read How to Pass Object as Parameter in JavaScript ? We'll see how to Pass an object as a Parameter in JavaScript. We can pass objects as parameters to functions just like we do with any other data type. passing objects as parameters to functions allows us to manipulate their properties within the function. These are the following approaches: Table of 3 min read Like