Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

197
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda