0

I have the following function, which itself contains a function.

var noisyFunction = function() {
    return function() {
      return "NOISY TOWN!"
    }
}

Now, when I call noisyFunction by using

var theNoisy = noisyFunction()

the return function is what is returned.

Is there any way to just get "NOISY TOWN!" returned? I do not think the nested function can be specifically called. I feel like I am missing something.

Appreciate any direction that could be provided.

MatthewS
  • 455
  • 2
  • 7
  • 22
  • You can do `noisyFunction()()` if you don't want an intermediate variable, however there is no way to just call the inner function without the outer one. – VLAZ Nov 22 '20 at 14:00
  • @VLAZ that was very helpful and did what I needed. Does ```noisyFunction()()``` call both the outer function and the inner function? Is that what is occurring? – MatthewS Nov 22 '20 at 14:08
  • Yes. The result of `noisyFunction()` is itself a function. Any value can be called as a function by appending `()` in the end. So, you just execute the result of the fist function. The same way you can do `parseInt("40").toFixed("2")` to call a number method on the result of `parseInt`, since it returns a number. – VLAZ Nov 22 '20 at 14:21

0 Answers0