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

199
Views
function with non declared variables / variables as functions

I have two questions regarding the following code sample:

function greaterThan(n) {
  return m => m > n;
}
let greaterThan10 = greaterThan(10);
console.log(greaterThan10(11));
//returns true

From what I understand the function greaterThan(n) returns a function which takes the parameter m but here it starts to get tricky for me:

  1. Why is this m not declared and still properly working within this code sample?
  2. greaterThan10 is declared as a variable in line 4 and it is inheriting the value of greaterThan(10). How can it behave like a function in line 5, where this "variable" takes another integer?
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

greaterThan is a higher order function; it returns another function that it creates based on the inputs.

m => m > n is an arrow function.

It's equivalent to this:

function greaterThan(n) {
  return function (m) {
    return m > n;
  }
}
let greaterThan10 = greaterThan(10);
console.log(greaterThan10(11));
//returns true

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!