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

176
Visualizações
I m getting confuse why I am getting the second Result first..?

function first() {
  console.log("first");
}

function second() {
  console.log("second");
}

first(second());

Now the issue is when I am calling (first function) this is giving me the (second) first, I just wanted to know what is exactly happening here how this is working..? and how the second function's value is passing inside first function..? (because there is no parameter inside first function)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Let's debug your code step by step.

First, the two functions are defined. Nothing wrong with that.

Then, you call the first function, first()

Javascript reads the line and looks at what's inside the parentheses so that it can pass the value into the function.

So now, it sees you called the second function, second(). Again, it looks at the parameters being passed. It sees nothing, so it passed nothing. The function you defined also accepts nothing, so it works! It prints out "Second" first. But you made the function return nothing. So, it's a null function. It returns null.

Right now, your code is first(null) because second() is null. In Javascript, myFunction(null) is mostly the same as myFunction(), so Javascript passes nothing into the function, and your first() functions also accepts nothing, and this works, printing out "First" second.

Javascript does go left to right, but usually, it executes commands in the deepest lowest nest of brackets so that it can pass the returning results to the next level of parentheses.

.

I suggest watching more Javascript videos online and learning them on w3schools or https://developer.mozilla.org/ as they have great examples and studies.

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