javascript
Pass a function as parameter of another function in Javascript
In javascript, if you have a function that executes a block of code and you want to pass this function as a parameter of another function. You can use the code examples explained here.
function message() {
return "Devsheet";
}
function print_message(my_function) {
var msg = my_function();
console.log(`Hello from ${msg}`);
}
print_message(message);
Output
Hello from Devsheet
Was this helpful?
Similar Posts
- Pass multiple arguments when calling a function which takes single argument Javascript
- Change autoCompleteTypes parameter in Google Autocomplete
- Navigate or link to another page React
- Replace array values with another value Lodash
- Run a function every 5 seconds interval using Javascript
- Run a Javascript function after user finished writing in the input field
- Assign default values to function parameters in Javascript