Open In App

Passing a function as a parameter in JavaScript

Last Updated : 13 Jun, 2023
Summarize
Comments
Improve
Suggest changes
Share
2 Likes
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. 


Output
hello User!

Example 2: This example passes a function geeks_inner along with an argument 'Geeks!' to the function geeks_outer as an argument. 


Output
hello 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.


Output
hello [Function: smaller]
Is everything alright
Hiii Geeks for Geeks

Similar Reads