0

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

1
  • This is working. What is the issue? You just need to call x() somewhere and call z() somewhere inside it. Commented Jan 27, 2022 at 19:40

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.