Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
Function as an argument
five = function(parameter1) {
  console.log(parameter1)
}

five(function() {
    var x = 5;
    return x;
})

I have passed an anonymous function as an argument to the five function, why is this function not logging 5?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

five = function(parameter1) {
  console.log(parameter1())
}

five(function () {
    var x = 5;
    return x;
})

Change it like this, and it should work.

you did not call the function you just made a reference to it.

about 4 years ago · Juan Pablo Isaza Report

0

five = function(parameter1) {
  console.log(parameter1()); // call the passed function
}

five(function() {
    var x = 5;
    return x;
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!