• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

140
Views
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()
  }
 
}

almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

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

almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error