Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda