Reputation: 13
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()
}
}
Upvotes: 0
Views: 47
Reputation: 30408
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
Upvotes: 2