Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading