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

185
Vistas
how to pass argument to child function in js
function checkSalary(baseSalary, bonus, tax) {
    console.log(baseSalary, bonus, tax)
    function salary(baseSalary, bonus) {
        console.log(baseSalary, bonus)
        return baseSalary + bonus;
    }
    function salary_with_tax(tax) {
        console.log(tax)

        return salary() - tax;
    }
}

console.log(checkSalary(5000, 3000, 100))


I want to check using salary() and salary_with_tax() but don't know how to pass the arguments.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You must call your inner functions at some point. Something like this:

I had to make some assumptions about what you want. I returned an object with the results of each inner function.

function checkSalary(baseSalary, bonus, tax) {
    console.log(baseSalary, bonus, tax)
    function salary(baseSalary, bonus) {
        console.log(baseSalary, bonus)
        return baseSalary + bonus;
    }
    function salary_with_tax(tax) {
        console.log(tax)

        return salary(baseSalary, bonus) - tax;
    }
    
    return {
      salary: salary(baseSalary, bonus),
      tax: salary_with_tax(tax)
    }
}

console.log(checkSalary(5000, 3000, 100))

about 4 years ago · Juan Pablo Isaza Denunciar

0

Javascript is much like many languages where you can defined functions within other functions, but until you actually call the function nothing happens. Just call the inner functions and get the result and do with it whatever you like.

There is also no need to re-define the arguments if theyre exactly the same names.

function checkSalary(baseSalary, bonus, tax) {

    function salary() {
        
        return baseSalary + bonus;
    }
    function salary_with_tax() {
        return salary() - tax;
    }
    
    const theSalary = salary()
    const theSalaryWithTax = salary_with_tax();
    
    console.log(theSalary, theSalaryWithTax);
    
    return "Foo"; // you can "check" whatever you like here, and return something more appropriate
}

console.log(checkSalary(5000, 3000, 100))

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