• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

150
Vistas
Calling JavaScript sibling function inside parent function

I’m struggling with this and I haven’t found anything conclusive about this.

How can I call the function y() inside the function z() without altering the code's structure?

I tried using this but it didn’t work.

function x(){

    function y(){
    console.log("sal y")
  }
  
  function z(){
    console.log("sal z");
    y()
  }
 
}

about 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your code inside z calls y in the correct way – that’s not the problem. The reason you’re not seeing output in your snippet is that you’re never calling function z. If I edit function x to call z, and I edit the top level to call function x, it works.

function x() {
  function y() {
    console.log("sal y");
  }

  function z() {
    console.log("sal z");
    y();
  }
  
  z(); // added
}

x(); // added

about 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda