From the course: JavaScript: Closures
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Return a value from an inner function - JavaScript Tutorial
From the course: JavaScript: Closures
Return a value from an inner function
- [Instructor] The third and final building block of closures is returning a value from a function. And in particular, returning a reference to an inner function. Whatever a function does, it mainly affects the app that it's part of by returning a value. Data goes in, and the data that comes out has been transformed in some way by the function. For instance, this function takes in data in the form of the base and tax parameters. It then uses those parameters in a calculation, that calculation results in a new value stored in the total variable. And finally, it returns this new value as the result of the function execution. In our updateClicks function, instead of simply calling report clicks at the end of the function, we can instead return a reference to the reportClicks function. And this has a few positive effects. First off, remember that including parentheses after a function name always calls the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.