I am calling a function on button click like this:
<input type="button" onclick="outer();" value="ACTION">
function outer() {
alert("hi");
}
It works fine and I get an alert:
Now when I do like this:
function outer() {
function inner() {
alert("hi");
}
}
Why don't I get an alert?
Though inner function has a scope available in outer function.
You can also try this.Here you are returning the function "inside" and invoking with the second set of parenthesis.
Or
The scoping is correct as you've noted. However, you are not calling the
inner
function anywhere.You can do either:
Or
You could make it into a module and expose your inner function by returning it in an Object.
You are not calling the function
inner
, just defining it.