I need to pass a function as a parameter in another function
javascript parmeter in js
Yes, it is possible to pass a function as a parameter in JavaScript. This is a common feature in JavaScript and is frequently used in higher-order functions, callback functions, and event handlers.
function greet(name) {
return `Hello, ${name}!`;
}
function displayGreeting(greetingFunction, name) {
console.log(greetingFunction(name));
}
displayGreeting(greet, 'Alice'); // Outputs: Hello
, Alice!
Test your knowledge with interactive quizzes.
Prepare for interviews with curated question sets.
Ask your coding-related doubts and get answers.
Earn certifications to enhance your resume.
Hands-on projects to improve your skills.
Test your knowledge with interactive quizzes.
Prepare for interviews with curated question sets.
Add your technical blogs and read technical topics.
Earn certifications to enhance your resume.
Hands-on projects to improve your skills.