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.

3
  • 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. Commented Nov 22, 2020 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? Commented Nov 22, 2020 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. Commented Nov 22, 2020 at 14:21

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.