Skip to main content

Is It Possible to Pass Function as Parameter in JS

Published: Asked By 1 Answers Answered
I need to pass a function as a parameter in another function
Share:

1 Answer

M
Mufeeda Community Contributor Answered on

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!

Your Answer

Other Resources

Quiz Image
Quiz

Test your knowledge with interactive quizzes.

Interview Questions Image
Interview Questions

Prepare for interviews with curated question sets.

Q&A Image
Q&A

Ask your coding-related doubts and get answers.

Certification Image
Certification

Earn certifications to enhance your resume.

internships Image
Internships

Hands-on projects to improve your skills.

Quiz Image
Quiz

Test your knowledge with interactive quizzes.

Interview Questions Image
Interview Questions

Prepare for interviews with curated question sets.

blog Image
Blogs

Add your technical blogs and read technical topics.

Certification Image
Certifications

Earn certifications to enhance your resume.